2 CPT's: 'movie' and 'cast-crew-member'. A many too many relationship 'movies-crew-member' with 1 checkbox custom field per function (director, screenwriter, composer). I need to create a view that will be added to the content template of the cpt 'movie'.
I need to list the intermediary posts where the checkbox 'director'=1. then retrieve the values of the custom fields 'first-name' and 'last-name' of the child post.
This is easy. to make with the Views blocks, but I need to create a php script and create a shortcode to add the sorting of the results based on the 'last-name'.
Can you help without accessing the admin as I'm working locally to develop ?
// Prepare the SQL query
$sql = $wpdb->prepare("
SELECT pm_child.meta_value AS child_id
FROM {$wpdb->posts} AS intermediate
INNER JOIN {$wpdb->postmeta} AS pm_parent
ON intermediate.ID = pm_parent.post_id AND pm_parent.meta_key = %s AND pm_parent.meta_value = %d
INNER JOIN {$wpdb->postmeta} AS pm_child
ON intermediate.ID = pm_child.post_id AND pm_child.meta_key = %s
INNER JOIN {$wpdb->postmeta} AS pm_director
ON intermediate.ID = pm_director.post_id AND pm_director.meta_key = %s AND pm_director.meta_value = '1'
WHERE intermediate.post_type = %s
AND intermediate.post_status = 'publish'
", "@{$relationship_slug}_parent", $movie_id, "@{$relationship_slug}_child", 'wpcf-crew-director', $intermediate_post_type);
$movie_id = $post->ID;
$relationship_slug = 'movies-crew-member';
$child_post_type = 'cast-and-crew-member';
$result = toolset_get_related_posts($movie_id,
$relationship_slug,
array(
'query_by_role' => 'parent', // origin post role
'role_to_return' => 'intermediary', // role of posts to return
'return' => 'post_object', // return array of IDs (post_id) or post objects (post_object)
'limit' => 999, // max number of results
'args' => array(
'meta_key' => 'wpcf-crew-director',
'meta_value' => '1',
), // Additional query arguments
'orderby' => 'meta_value',
'orderby_role' => 'intermediary',
'order' => 'ASC',
));
I that does not work, You will have to host your site on any server and send me admin access details and problem URL so I can review your current structure and guide you accordingly.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) 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.