1

I am trying to load custom category post of custom_post_type using Ajax.

I have taken help from Load categories with ajax

The content is loading properly for default categories but not for my custom_post_type Category.

I have made little change in function for custom post_type:

$args = array (
        'cat' => $cat_id,
        'posts_per_page' => 3,
        'order' => 'DESC',
        'post_type' => 'collections'
      );

Please help me to load custom post...

0

There is no "custom_post_type Category" and the custom post type is not related to categories by default.

To understand it you need to visualize it like this: the WordPress default post type is called post and the default taxonomy is called category. and they are related by default in WordPress core. I am mentioning this because in your query you use the cat parameter which will search for the default category which isn't linked to your custom post type.

You could link them like this after you register your custom post type:

register_taxonomy_for_object_type( 'category', 'collections' );

I can't recommend you the above since is harder to manage and creates weird logics.

My recommendation: if you create a custom post type(collections) you need to register a new taxonomy(maybe called collections_category) and link it to your collections. Then you could query like this:

$args = array (
    'posts_per_page' => 3,
    'order' => 'DESC',
    'post_type' => 'collections',
    'tax_query' => array(
        array(
            'taxonomy' => 'collections_category',
            'field'    => 'term_id',
            'terms'    => array( $cat_id ),
        ),
    ),
  );
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.