Problem:
parent post type: "contatto" with types custom field "data-inizio-ultimo-corso"
child post type: "corso" with types custom field "data-inizio-corso"
i'm using view filtering only "contatto" post types (because we don't want to see duplicates)
when submitting a new "corso", i'm updating "data-inizio-ultimo -corso" if date greater, using this function:
//DATA INIZIO ULTIMO CORSO function inserisce_data_inizio_ultimo_corso( $post_ID ) { if ( get_post_type( $post_ID ) == 'corso' ) { $data_inizio_corso_inserito_timestamp = get_post_meta($post_ID, 'wpcf-data-inizio-corso', true); $contatto_id = get_post_meta($post_ID, '_wpcf_belongs_contatto_id', true); $data_inizio_corso_attuale_timestamp = get_post_meta( $contatto_id, 'wpcf-data-inizio-ultimo-corso', true ); if ( $data_inizio_corso_inserito_timestamp > $data_inizio_corso_attuale_timestamp) {update_post_meta( $contatto_id, 'wpcf-data-inizio-ultimo-corso', $data_inizio_corso_inserito_timestamp );} } } add_action( 'save_post', 'inserisce_data_inizio_ultimo_corso', 99 );
Solution:
I assume you are going to check other child "corso" posts of same parent "contatto" post, in your PHP codes.
In your PHP codes, you can get the parent "contatto" post ID by this:
$contatto_id = get_post_meta($post_ID, '_wpcf_belongs_contatto_id', true);
With the "contatto" post ID, you can get all the child "corso" posts with wordpress function get_posts(), by the custom field "_wpcf_belongs_contatto_id", see our document:
section "Example of a custom query for displaying child posts"
Relevant Documentation:
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 |
---|---|---|---|---|---|---|
- | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Hong_Kong (GMT+08:00)
This topic contains 4 replies, has 2 voices.
Last updated by 6 years, 10 months ago.
Assisted by: Luo Yang.