I have "workshop" parents with "scheduled event" children. I would like to have a search page where I can filter on scheduled events by the "workshop" parent. So, I need some way to tag the parent "workshop" as scheduled IF it has 1 or more children and remove that tag when those children expire or are deleted.
Is there any documentation that you are following? couldn't find anything relevant
What is the link to your site? hidden link hidden link
Hello. Thank you for contacting the Toolset support.
What if you try to save the tag for the parent when you save the child post. That means when you save child post that means parent has child and you should update the field for the parent accordingly.
Here is what I tried. It isn't working. I also would like to add a way to say that, if the only assigned event post is expired then set the scheduled field to unchecked.
Parent post type slug = workshop
Child post type slug = event
Workshop custom field check box slug = scheduled
//Auto mark workshops as scheduled if they have an an event child that isn't expired
function is_scheduled( $post_id, $post ){
if ( 'workshop' == $post->post_type ) {
$child_posts = types_child_posts('event');
if ($child_posts) {
return true;
}
update_post_meta( $post_id, 'wpcf-scheduled', 1 );
}
}
add_action( 'save_post', 'is_scheduled', 30, 2 );
Can you please share the problem URL and access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Can you please check now. I've added the following code to the "Custom Code" section:
=> hidden link
//Auto mark workshops as scheduled if they have an an event child that isn't expired
function func_is_scheduled( $post_id, $post ){
if ( 'workshop' == $post->post_type ) {
$child_posts = toolset_get_related_posts($post_id,'workshop-info-event','parent',999,0,array(),'post_id','child');
if(count($child_posts) > 0){
update_post_meta( $post_id,'wpcf-scheduled',1);
}
}
}
add_action( 'save_post', 'func_is_scheduled', 100, 3 );
For the testing purpose, the following Workshop has the event, you should uncheck the "Scheduled" checkbox and save the post, as this workshop has one event available the checkbox will be automatically checked.
=> hidden link
I would like to add a little more logic to this code to say that
1. if the there are no children or
2. if all the children are expired then
automatically un-check the "scheduled" box (set to 0?).
Can you please help with that?
P.S.
I added the expiration date in the theme editor > functions.php file:
* Add expiration date to event custom post type
*
*/
function mycustomposttype_add_expire_date_metabox() {
add_meta_box( 'hugu_ped_expire_date_metabox', __( 'Expiration Date', 'hugu'), 'hugu_ped_expire_date_metabox_callback', array( 'mycustomposttype', 'event' ), 'side', 'high' );
}
add_action( 'add_meta_boxes', 'mycustomposttype_add_expire_date_metabox' );