Getting related "posts" from a custom post type
-
Hi! I have two custom post types:
– Artists
– ReleasesAnd I have extended the WordPress posts by adding two fields. One for “related artists” and one for “related releases”.
In my single-release template I can get the related posts by doing the following query:
$args = array( 'post_type' => 'post', 'meta_query' => array( array( 'key' => 'posts_related_to_release', 'value' => get_the_ID(), 'compare' => 'CONTAINS' )) ); $query = new WP_Query($args); ?> <?php if ( $query->have_posts() ): ?> ...Showing stuff <?php endif; ?>
This works great. But NOT when I’m doing the same query from the single-artist page like this:
$args = array( 'post_type' => 'post', 'meta_query' => array( array( 'key' => 'post_related_to_artist', 'value' => get_the_ID(), 'compare' => 'CONTAINS' )) ); $query = new WP_Query($args); ?> <?php if ( $query->have_posts() ): ?> ...Showing stuff <?php endif; ?>
I tried to var_dump the meta fields on a single-post template like this:
<?php var_dump( get_post_meta(get_the_ID(), 'post_related_to_release', true) ); ?> <?php var_dump( get_post_meta(get_the_ID(), 'post_related_to_artist', true) ); ?>
Which successfully prints out all the content from the related release and artist:
https://www.dropbox.com/s/3ldz5rfu3cjf5bm/Screenshot%202014-09-16%2011.10.59.png?dl=0What am I missing here? Why can I query the posts from the post_related_to_release field but not the post_related_to_artist field?
Here’s a screenshot of my pods settings:
https://www.dropbox.com/s/c3a2muzbppbaq4s/Screenshot%202014-09-16%2011.09.33.png?dl=0
- The topic ‘Getting related "posts" from a custom post type’ is closed to new replies.