On our site we currently have ‘work’ posts that we create and then associate with an author and genre post type.
The overall goal is:
When we view an author or genre post we want to list all the work posts that we have associated/related with that certain author/genre.
We are using the following code which seems to have us half way…
<?php $args = array(
'numberposts' => -1,
'post_type' => 'post',
'meta_query' => array(
array(
'key' => 'related_posts',
'value' => $post->id
)
)
);
$posts_array = get_posts( $args );
var_dump($posts_array);
if( $posts_array ) {
echo '<ul>';
foreach( $posts_array as $related ) {
echo '<li>';
echo '<a href="' . $related->guid . '">' . $related->post_title . '</a>';
echo '</li>';
}
echo '</ul>';
}
?>
However the ‘value’ field in the array doesn’t work. It technically should be passing the id of the current post (author or genre) and selecting the related content. When we remove this from the array it does bring all the posts in whether they are related or not.
In summary, we think that the ‘value’ problem may be the key in resolving the issue as that is what should be filtering the posts.
Thanks in advance
did you try
$post->ID
? (uppercase not lowercase)