CustomPress CPT not showing up in search results by Category

Hi everyone,

I made a custom post type using CustomPress. I allowed it to have tags and categories, and included TRUE regarding querying and showing up in search results. It's also set to public and I think that everything is correctly set.

When I try to create a file called category-slug.php, and I do a query, regular posts are showing up but not the CPT's. I have searched for hours but to no avail.

Can anyone help me out here? I'm kind of lost.

Thanks !!

  • Michael
    • The Incredible Code Injector

    Hi Predrag,

    I did some "testing" and it's not about the "category-slug" file. The CPT's made by custompress simply don't show up when categorised. For example, see the screenshot. Although the get_category_list shows there's one item found in the query, it doesn't show up visually. Weird.

    In this example (sorry, it is in dutch) you can see that there's a subcategory "jongeren", indicating that there's one item found (post count in get_category_list). Weird thing is that it isn't shown.

    I did a local reinstall export/import the custompress items and it gives the same results.

    I can grant support access when needed.

    Thanks for all the help as always!

  • Predrag Dubajic
    • Support

    Hi Michael,

    It looks like the support access has expired so I couldn't access your site, can you try enable it again so we can export your CustomPress settings and perform couple of tests on our end?

    Please let us know which subsite and CPT are in questions as well :slight_smile:

    Best regards,
    Predrag

  • Predrag Dubajic
    • Support

    Hi Michael,

    Thanks for the access and additional details, I was doing some testing based on that and it looks like this is an issue with the plugin itself because it's using CPT category as a default post category and that category on the front end will actually list only regular posts in that category.

    I have gathered all the information I got during the testing and created a bug report so our developers can check what's going on.

    Thanks for bringing this up to our attention!

    Best regards,
    Predrag

  • Michael
    • The Incredible Code Injector

    Predrag FYI: although you "are on it" and it is a bug in the plugin and because it's a bit urgent, I was looking for a workaround. I read that creating a custom taxonomy for the CPT and include that taxonomy in the loop, might solve the problem. I will try that out today.

    • Predrag Dubajic
      • Support

      Hi Michael,

      Custom taxonomy should work fine, and I confirmed it works on my installation, because this is a separate taxonomy while CustomPress currently uses default categories as CPT categories and that causes it to show only default WP posts in query instead of your CPT.

      Best regards,
      Predrag

      • Michael
        • The Incredible Code Injector

        Ok thanks for the heads up. I'll stand down a bit then knowing there is a workaround. But I'll wait and see if the CPT's show up while performing a normal search, because otherwise I might mess other things up. Thanks !

  • Michael
    • The Incredible Code Injector

    Is there any news on this please? My main issues remain and I have no working... workaround :wink:

    My main problems now are:
    1. the CPT doesn't show up in the category list although the count is ok
    2. the CPT is not included in search

    Thanks !

    kind regards

  • Michael
    • The Incredible Code Injector

    I'm not sure if this code is useful, but I'm to "green" to implement it on the fly:

    function add_custom_types_to_tax( $query ) {
    if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
    
    // Get all your post types
    $post_types = get_post_types();
    
    $query->set( 'post_type', $post_types );
    return $query;
    }
    }
    add_filter( 'pre_get_posts', 'add_custom_types_to_tax' );

    Source

  • Predrag Dubajic
    • Support

    Hi Michael,

    I'm afraid that I don't have any news from the dev yet but that's a nice find there and the code seems to be working fine on my end.

    That code can be added as a mu-plugin so you can create one yourself or download the attached file, unzip it and place it inside wp-content/mu-plugins/ folder, if you don't have that folder simply create one yourself.

    Once the file is there that should be it, the code will be loaded and you should see your CTP in categories and search pages.

    Best regards,
    Predrag

  • Michael
    • The Incredible Code Injector

    Hi Predrag,

    I have a multisite so I did the following:

    1. create a mu-plugin directory
    2. copied your file in there
    3. went to Network Admin | Update Network

    Although it is only minutes ago I didn't see any difference. On this link, it still says count=3 in the category sidebar, but it doesn't show up any posts.

    I'm starting to think that it's because of my incomplete knowledge of WP development, that I'm making an essential mistake here. I can't imagine that, off all the users of CustomPress, I'm the only one having this problem :wink:

    What I'm going to do, is to make a basic page with one Custom Query Loop to one CustomPress-created custom post type. That rules out a lot.

    I'll keep you posted and thanks for the help!

  • Michael
    • The Incredible Code Injector

    Oh, I get a weird error now when accessing the CustomPress custom post types:

    bookmark88(rs/P z?w???AT ApplicationsMAMPhtdocs CustomPress wp-content mu-plugins aspodi.php$0@Th|??9@?d[?f?s???1?:?????A??? file:///Untitled8?A??ra$BDEF96A5-9031-3296-9032-F7AD30B049E6???/3dnibphp??????????$X@H  ? ? ? ? ? ?0 x?x??|"?

  • Michael
    • The Incredible Code Injector

    Predrag: progression: I created a page-afdelingen.php with a simple custom query loop. (afdelingen is one of the CustomPress created CPT's)

    And lo and behold...

    So I must have forgotten something in the category.php file. Question is... what?

    Note to self: the usual suspect is the loop itself. Posts=any, status=published, ...

    I'm going to investigate this further, if you can help, that would be nice. That way, I can write down the solution here in case others have the same problem.

  • Michael
    • The Incredible Code Injector

    Well, after hours of searching, testing and *%°è%* I tried to exclude a plugin problem. Therefor, I installed Custom Post Types UI and quickly added a CPT. This resulted in the same problem.

    So it must be something with my theme, I think.

  • Michael
    • The Incredible Code Injector

    Ok, I did the following:
    1. disabled all plugins except custom press
    2. changed theme to a default one

    But still no results. I'm out of ideas now. It looks like CPT's are simply not registered like posts, or something.

  • Michael
    • The Incredible Code Injector

    I don't know if this is good news, or bad...

    I decided to reinstall the CustomPress plugin. After reinstall, I had a look at the settings page. I noticed, that after a reinstall so I guess by default, the checkboxes saying:

    "If "default" is checked the list above will be disabled and only default post_types will display."

    were checked. So I unchecked them. The page reloaded and I noticed they were checked again. So I unchecked them. Same issue. I cleared my browsers cache, reloaded the page. Same issue.

    I was stunned. Must be a setting elsewhere. So I opened a private windows in the browser, logged in, unchecked them again and: SOLVED! Checked the site and everything was working fine !

    So all of this was due to some kind of caching bug?! I have no idea but the problem is solved so for those who run into the same problem:

    - on multisite, check the custom press plugin settings on site level (NOT Network super admin level) and make sure that the default checkboxes are turned off.
    - single site: well, the same :wink:

  • Predrag Dubajic
    • Support

    Hi Michael,

    Glad to hear it's working for you now, I did some tests on my end and was able to save these settings without any issues and since it's working for you in incognito mode there's probably some caching on your end that prevented it from saving.

    A little explanation about the mu-plugin I mentioned above.
    MU stands for Must Use, and once you place a file inside wp-content/mu-plugins folder (note that it's mu-plugins, with S at the end) the plugin will be automatically active on all your subsites and there will be no option to activate or deactivate it.
    You will also see Must-Use filter inside your Plugins panel where you will see list of mu-plugins you have on your installation.

    Best regards,
    Predrag

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.