Home Forums General Issues Display posts by category


Display posts by category

  • Hello. Enthusiastic newbie here. I am trying to display posts by category.
    I have set up the taxonomy as below and assigned categories to products.

    function taxonomy ()

    $args = array (

    ‘labels’ => array(

    ‘name’ => ‘Category’,
    ‘singular_name’ => ‘Category’,
    ‘public’ => true,
    ‘hierarchical’ => true, //set to false to make it appear or function more like tags. True means categories.


    register_taxonomy(‘name’, array(‘products’), $args);

    add_action(‘init’, ‘taxonomy’);

    The page output is:

    <?php if(have_posts()):while(have_posts()): the_post();?>

    I want to add in here something like:

    <?php if( in_category(‘cat1’) || cat_is_ancestor_of(‘cat1’, $current_category) ) {

    — then display these posts —


    Any help would be greatly appreciated.

  • This is really a general WP question and not related to ACF.

    First off, if this is showing only posts in one category then you need should have a taxonomy template "taxonomy-{$taxonomy}.php" or a term template "taxonomy-{$taxonomy}-{$term}.php"

    If you are trying to show multiple terms and sort the posts by term, this is not something that is native to WP. You need to get the list of terms and then loop over them doing a separate post query for each term,

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

You must be logged in to reply to this topic.