Title: Querying by post category
Last modified: June 12, 2020

---

# Querying by post category

 *  [lgehrig4](https://wordpress.org/support/users/lgehrig4/)
 * (@lgehrig4)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/querying-by-post-category/)
 * I’m creating a custom theme with 2 blog pages. The first blog uses the wordpress
   provided post and the second a custom post. Both have categories. Both pages 
   are loading properly. Everything, from what I can tell is the same for blogs 
   aside from the post data.
 * The problem is that no posts are loading when a category is clicked on the custom
   post page. The url is correct but only the header/footer and page title load.
   The other page works fine in this regard.
 * All the categories look correct in the dashboard and show the respective number
   of posts in each.
 * I’m not sure how to troubleshoot this one. Any suggestions on where I should 
   start?
    -  This topic was modified 5 years, 11 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/querying-by-post-category/#post-12972112)
 * Check your error log (you should have WP_DEBUG on for development). It sounds
   like there was an error before the page finished output.
    Compare what is different
   from your theme to a theme that works.
 *  Thread Starter [lgehrig4](https://wordpress.org/support/users/lgehrig4/)
 * (@lgehrig4)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/querying-by-post-category/#post-12974344)
 * Thanks [@joyously](https://wordpress.org/support/users/joyously/). I don’t think
   it helped in this case but this is someone that I wasn’t aware of that I’m sure
   will come in handy.
 * This is the only error in the log
 * **[12-Jun-2020 00:42:39 UTC] PHP Warning: Use of undefined constant all – assumed‘
   all’ (this will throw an Error in a future version of PHP) in /Applications/MAMP/
   htdocs/wordpress2/wp-content/themes/theindependentinvestor/functions.php on line
   8**
 * This is the line that it’s referring to which is only for the styleheet
 * `wp_enqueue_style('style', get_stylesheet_uri(), NULL, microtime(), all);`
 *  Thread Starter [lgehrig4](https://wordpress.org/support/users/lgehrig4/)
 * (@lgehrig4)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/querying-by-post-category/#post-12974429)
 * Found this issue. I had to register the categories for the custom posts. I can
   see where this would be a problem if this was going to be a real production site.
   You wouldn’t be able to add new categories in the dashboard.
 * This was the fix for my situation
 *     ```
       function my_query_post_type($query) {
           if ( is_category() && ( ! isset( $query->query_vars['suppress_filters'] ) || false == $query->query_vars['suppress_filters'] ) ) {
               $query->set( 'post_type', array( 'invest', 
                 'Advisors',
                 'Cryptocurrencies',
                 'Derivatives',
                 'Equities',
               ));
               return $query;
           }
       }
   
       add_filter('pre_get_posts', 'my_query_post_type');
       ```
   
 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/querying-by-post-category/#post-12974486)
 * The warning is saying that `all` should be `'all'`, so it’s a string instead 
   of an undefined constant.
 * Should your code for post_type be the slugs?
 *  Thread Starter [lgehrig4](https://wordpress.org/support/users/lgehrig4/)
 * (@lgehrig4)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/querying-by-post-category/#post-12974533)
 * Corrected that thanks. That was just a response I found on another thread asking
   the same question so I don’t fully understand what it all means. I just replaced
   the categories with mine.
 * That said I spoke too soon. After including this code the posts from my custom
   post page displayed together by category when the category was clicked. However,
   the posts from the other post page (wordpress default or whatever you call it)
   stopped working when a category was clicked. Fixed one post page and broke the
   other.
 * Back to square one

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Querying by post category’ is closed to new replies.

## Tags

 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [custom post](https://wordpress.org/support/topic-tag/custom-post/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [lgehrig4](https://wordpress.org/support/users/lgehrig4/)
 * Last activity: [5 years, 11 months ago](https://wordpress.org/support/topic/querying-by-post-category/#post-12974533)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
