Home Forums Front-end Issues Can't use "categories" to output CPTs


Can't use "categories" to output CPTs

  • 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'
    					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:

    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!

  • Hi @oxygensmith

    This is a general WP question which does not belong on this ACF support forum.
    Please consult google / WP for this as it is not related to ACF.


Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Can't use "categories" to output CPTs’ is closed to new replies.