• Hello World!

    I am trying to get all Product-Posts (Custom Post Type: product) by Category ID but it doesn’t work.

    Can you help me?

    get_posts(array('category' => 13, 'post_type' => 'product'));

    The Products Post Type taxonomy is the standard WordPress Core “category”.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I have exactly the same problem…

    For me it works. In my category page I have this:

    <?php get_header(); ?>
        <?php
            //false -> stops displaying title on screen.
            $cat_name = single_cat_title('', false);
    
            $this_cat = get_category_object($cat_name);
            $cat_id = $this_cat->term_id;
        ?>
        <?php
            $args = array('category' => $cat_id, 'post_type' => 'trips');
            $posts = get_posts($args);
            foreach($posts as $post) : setup_postdata($post); ?>
                <h1><?php the_title(); ?></h1>
            <?php endforeach;
        ?>
    <?php get_footer(); ?>

    For me Trips is a custom post type and all the categories are standard WordPress categories like yours.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get Custom Posts By Category ID’ is closed to new replies.