Hey Elliot,
I’m just confused by something which isn’t covered in your code examples.
I’ve built the Custom Post Types manually through the register_post_type method, and taxonomies for said CPTs are made through register_taxonomy. These are configured through creating a custom site plugin rather than functions.php (so I can switch themes and still retain the custom post types.).
Then I go to set up the fields through ACF and all the data entry and output works fine.
The only issue with output that I’m having is that if I use the code examples provided, if I add the parameter “category” to the get_posts method of retrieving CPTs, nothing shows up.
So here is my code for a custom post type called “books” (to output the book entries in random order):
$posts = get_posts(array(
'numberposts' => -1,
'orderby' => 'rand',
'post_type' => 'books'
));
if($posts)
{
foreach($posts as $post)
{
echo '<!-- Book: ' . get_the_title($post->ID) . '-->';
$image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'medium');
echo '<div class="entry-books"><a href="' . get_permalink($post->ID) . '"><img src="'. $image_url[0] . '" alt="' . get_the_title($post->ID) . '"/></a></div>';
}
}
That works really well. But if I add category => 3 or category => ‘3’ to the parameter list, the front-end code spits out no books.
I’m sure that the category I am looking for has the ID ‘3.’ When I hover over the category “New Releases” in the “Books Set” taxonomy I created (on the Dashboard > Books > Books Set), I get:
http://oursite.ca/wp-admin/edit-tags.php?action=edit&taxonomy=books_taxonomy&tag_ID=3&post_type=books
And books are definitely set to that category.
Is there any other code I can show you to demonstrate the issue?
Thanks for your help!