Skip Navigation

[Resolved] Split: Dynamic Post Groups based on field or taxonomy values

This support ticket is created 6 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Christian Cox 6 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1141180

By GUI it's not possible to assign Custom Post Groups to single Posts based on conditions.

Example:
Access Post Group A should be only assigned to Posts with Term "ABC" assigned, but never to posts with term "DEF" assigned.
For those, Access Post Group B should be used.

Supporter Beda mentioned this can be done with custom code.

I am here to get informations about what I need to observe when writing this code, where Toolset stores the information, etc, so I can craft a Custom Code, that automatically sets the correct Access Post Group to the posts depending on a condition (which can be Terms, in the example, or whatever else)

#1141575

Hi, essentially you'll be updating a custom field value in the database. The field slug is _wpcf_access_group and the value has a unique hash like this: wpcf-custom-group-1584797355f2d242ba5c8c879e748829. In order to determine the correct unique hash for each post group, you'll need to check in the database. Assign each post group to some post, then you can find the _wpcf_access_group entry for each of those posts in the postmeta table. Copy the corresponding meta_values for each post group and paste them in your custom code.

Here's an example showing how to modify a post group for some post:

update_post_meta($post_id,'_wpcf_access_group','wpcf-custom-group-1584797355f2d242ba5c8c879e748829');

Use the save_post action with a minimum priority of 15 to hook into the post save process.

add_action( 'save_post', 'automate_group', 100, 3 );
function automate_group( $post_id, $post, $update ) {
  // add your code here to test the post's terms or custom field values 
  // and apply the correct post group
}

https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
https://codex.wordpress.org/Function_Reference/update_post_meta