Hi,
1. Create a custom post with type “cuar_smart_group” using the WordPress functions to save a post. Remember the post ID, that’s your group ID. We’ll call it $group_id.
2. Create the critera associated to that group
2.1. Get access to the addon:
$sg_addon = cuar_addon('smart-groups');
2.2. Then you can use its functions:
$sg_addon->enable_meta_criteria(
$group_id, // The group ID from above
'AND', // You can use OR, but same thing if you have a single criteria
array(
array(
'compare' => '=',
'field' => 'Code',
'value' => 'ACT'
),
// Add more such arrays here to combine multiple criteria
)
);
That should get you started.
Hey Vincent, I managed to find existing and create new Smart Groups using my custom user field ‘Code’ – thank you.
But I can’t seem to figure out how to associate my smart group with my newly created file.
By examining the database I can see entries in the postmeta table for cuar_owner_type etc but can’t figure out which of your functions does the hard work.
Hope you can point me in the right direction (again)
Thanks Vincent
Something like that ($post_id being the ID of the private content):
$po_addon = cuar_addon('post-owner');
$po_addon->save_post_owners($post_id, array(
'usr' => array(1), // Owner will be the user with ID 1
'mgrp' => array(151), // Also assign to managed group with ID 151
));
Thanks Vincent – strange things:
1. Syntax was save_post_owners($postID, array(groupID), ‘sgrp’)
2. If runs to completion and the Files dashboard shows the correct Smart Group assignment
e.g. Smart Group – FSF
BUT when I edit the file, the Assignment box says Smart Group but nothing is displayed.
Is there a final ‘commit” type step?
TIA
Ah wait – that might be because the smart group didn’t get created properly – hold that thought…
Nailed it!! Thanks for all your help Vincent π
The code I gave you is working with version 7.x. For 6.x the method has different parameters indeed.
Woohoo!! All works a treat!!!! Thanks Vincent π
Hi Vincent,
I am trying to create a custom field code for my smart groups plugin add-on using the method you laid out for Paul. It is generating my post alright and it is showing up in my smart groups admin area but the criteria is not setting or throwing any exceptions. I’m not too sure what else could be wrong. Here is my code:
$sg_addon = cuar_addon('smart-groups');
//Generate smart group
$sg_addon->enable_meta_criteria(
$group_id,'OR',array(
array(
'compare' => '=',
'field' => 'company',
'value' => $this->user_company
)//I removed the comma since I only have the one criteria but it doesn't seem to make a difference, if I use it with or without the comma
// Add more such arrays here to combine multiple criteria
)
);
Where $group_id is the id of my post that is showing up in the smart group area. When I print out the class property user_company I am getting the right result and I can create the group manually.
Any thoughts on what I’m doing wrong? Thanks in advance.