0

I have a custom post type which is called "scholarship". Archive page for custom post type is disabled. I am using category (Scholarships) which also has subcategories. I have used following code to include CPT in loop.

function add_custom_post_type_to_query( $query ) {
if ( $query->is_home() || is_category() && $query->is_main_query() ) {
    $query->set( 'post_type', array('post', 'scholarship') );
} } add_action( 'pre_get_posts', 'add_custom_post_type_to_query' );

When i use this code, 5 CPT are showing up. Total are 8. CPT in Scholarships-subcategories are not showing up and after putting this code my all menus disappear. I have main menu plus one custom menu in footer. If any one could help please.

  • how do you make the query ? e.g. with get_posts the default pagination is set to 5 posts per page codex.wordpress.org/Function_Reference/get_posts – mmm Jul 30 '16 at 6:26
  • Default pagination is set to 12 posts and posts are working all right. problem is just with custom post type (scholarship) – Allen Jul 30 '16 at 6:35
  • This is the error on single custom post type: Fatal error: Cannot use object of type WP_Error as array in /home1/ab95613/ideabroad.com/wp-content/themes/ibf12/includes/wp_booster/td_page_generator.php on line 126 – Allen Jul 30 '16 at 6:41
  • your if statement evaluates to true for any query where is_home is true, which includes menus and secondary queries on the page. also, a helpful debugging method is to inspect the contents of $wp_query in your template, you will see how the query vars are set and the SQL query being sent to the database. – Milo Jul 30 '16 at 15:50
0

What you need to do is , first create a the CPT. Once the CPT with scholarship is created then create your custom taxonomy i.e scholarship which will be hierarchal.

So when you will add your custom taxonomy as scholarship, then in the 2nd argument please provide the slug of your CPT ie. "scholarship".

register_taxonomy( 'scholarship', 'scholarship', $args );

Hope this helps

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.