I have two post types that I've associated in one direction by assigning Post A as a custom meta field of Post B. I need to search based on the titles of Post A and return the associated Post B results. This feels a little tricky.
Normally I can display titles from Post A like so:
$post = get_post($post_id); $author_post_id = get_post_meta($post->ID, 'custom_author', true); $post_object = get_post( $author_post_id ); echo get_the_title($post_object);
And I believe I'm using
meta_query correctly to search Post B:
$args = array( 'post_type' => 'journal_entry', 'meta_query' => array( array( 'key' => 'custom_author', 'compare' => 'LIKE' ) ) ); $query = new WP_Query( $args ); if ( $query->have_posts() ): while ( $query->have_posts() ) : $query->the_post(); // Loop endwhile; endif; // Reset post data wp_reset_postdata();
But I think I need to shoehorn
get_the_title into my
meta_query value. I think. I'm a little turned around. Am I on the correct path?