Skip Navigation

[Resolved] category archive not showing native posts for a category only custom post type

This support ticket is created 5 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 17 replies, has 2 voices.

Last updated by Eric Manherz 5 years ago.

Assisted by: Nigel.

Author
Posts
#1628051

I am trying to:
show an archive containing both native and custom posts
Link to a page where the issue can be seen:
hidden link
I expected to see:
both articles and property type posts as on on the home page

Instead, I got: only property type posts are showing and none of the native post types are showing ( you can see what the native posts are on the home page.

If i turn off the Toolset blocks plugin the native posts are showing in that slug if it turn it back on it's limited again to only custom posts.

#1628557

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Screenshot 2020-05-18 at 08.37.31.png

Hi Eric

You are using the Blocks plugin (rather than Views).

Does that mean you are using the Block editor for your custom archive? Or was it made with the classic Views editor?

If you are using the Views editor then you can specify which post types to include in the category archive, as shown in the screenshot.

Can you check that to see what post types are listed?

If the standard Posts type is missing you can add it.

#1629335

I used the block editor for the archive - I selected in the loop selection Home/Blog, Search Results and Categories - categories which are used also by the Properties.

Tried to upload an image of that selection but the upload button here doesn't seem to work. That is when I look at the

if I go to the following hidden link the regular posts don't appear yet it's using the same Home/Blog Properties Archive and if it go to edit the design from the front end the same selections are made and actually when i'm editing the design the regular posts are showing up well in the editor.

If you need a userid and password I can set you up one if you'd like to see.

Cheers,
Eric

#1629357

I also have an old test site which was using the views rather than the blocks module and it does the same thing. hidden link

#1629805

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

I've tried to reproduce the same on my own site but I can't, it works correctly.

Can I get access to your site? I may want to take a copy for testing.

Let me mark your next reply as private so that I can get log-in credentials from you—you may want to create a temporary admin user for me to use that you can later delete. And be sure to have a current backup.

#1630561

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Screenshot 2020-05-19 at 15.34.21.png

Hi Eric

I took a copy of your site because I needed to do some debugging steps that I don't want to do on your live site.

Even after disabling all plugins (including Toolset) and switching theme to twentytwenty I notice there appears to be a problem with your data.

Go to Dashboard > Posts > Categories to list the categories and—as you can see in the screenshot—it says there are 158 categories, but you can only paginate through a little over 20 of them.

"Article" (from your example URL to demonstrate the problem) is missing, you'll note, but if you search for it you'll find it, and look closely and you will see the link to the archive on the front end is "hidden link". Note the double slash.

So this is on your site with everything disabled, including Toolset.

I'm still looking to see why, but this is my current line of enquiry, as with this broken I would say it is expected you would get unexpected results on the custom archives.

#1630689

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

It looks like you made changes to the categories over time or perhaps imported the data and something went wrong.

So, looking at the entries in the database, I can see that the Article category (along with others) says it is a child category of a category with term_id of 2, but there is no such category with that id, it must have been deleted, but done in such a way that the child categories were left orphaned.

That would explain why the URL of the archive for the "article" archive has double-slashes, the parent is null and missing (between the slashes).

I don't know if you have any details about the history of the site which would explain what broke your categories in this way?

I don't want to make any changes to your live site, but I can try some crude database updates on the copy (e.g. setting all orphaned categories to be top-level categories).

#1630921

thanks that would be great - a lot of categories were under a parent category of neighbourhoods but otherwise not sure how that happened. Site was originally a drupal site long ago. Is there no way to just edit the article category and make it a parent?

#1630925

I did have plugins attached at one point that removed a slug of property as I used to get urls of propery/property
Not sure if that might have done something

#1630927

also interesting is the the posts now are only showing those 20 or so categories or so in the block editor so somehow the categories for properties and posts have become separate.

#1631141

I tried changing the database on my staging site all the categories of parent 2 are set to zero and also those in group 2 are set to zero. This allows the proper showing of all the categories when editing a post or property but still when going to a category slug for article or any other it shows only the property type posts and not the normal posts.

Interestingly if you go to one of those posts and from the from edit the design for the Home/Blog Properties archive while you are editing it in block mode it is showing preview of both article and property posts in the editor window.4

#1631487

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Screenshot 2020-05-20 at 07.51.46.png
Screenshot 2020-05-20 at 07.51.11.png
Screenshot 2020-05-20 at 08.24.41.png

I ran SQL queries to fix the parent category (reset it to zero) for the problem categories as well as re-setting the term_group to zero in wp_terms, and that helped restore those missing categories when listing categories on my local copy.

But it didn't solve the problem of what appears on the category archive.

There is still something fundamentally wrong with your data, though.

In the screenshots you can see that when listing posts it reports that the latest post "About Judy Manherz" has the categories Article, Realtor, and Team. But when you edit the actual post in the second screenshot you can see that it reports that the post has no categories assigned, and not only that but there are no existing categories to choose from.

And this happens with all plugins disabled and the twentytwenty theme.

So while there are underlying problems with your data I think it is expected that anything dependent on categories will not necessarily work as intended.

When you make a custom WordPress Archive for categories, the post types included in the query will by default be any post type that categories are assigned to. Using the block editor to create the archive currently doesn't let you change this, but the classic editor does.

With the Query Monitor plugin I was able to see that visiting site.com/category/article it was only including the property post type in the query, and not built-in Posts.

So on your local site I deactivated the custom archive for categories and created a new one with the classic editor.

There I can see that by default it only wants to include Properties (screenshot), which must be connected to the underlying problems with the data. So I can go ahead and change that so that it includes both Posts and Properties, and then the archive works as intended on the front-end, returning both posts and properties.

But this means that you need to create and design the archive with the classic editor and not with blocks (go to Toolset > Settings and you can choose which editor to use when making a new archive).

If the underlying problems with the data are resolved I would expect it to be possible to create a new archive and for the assigned post types to all be included, and if not I could investigate further, but the data problems would need addressing first.

#1632245

Thanks very much for all that info and testing - I will try that - not sure what can be fixed with the data at this point but if I make the archive using the standard editor I suppose I can't automatically get any of the block styling features into the archive which was sort of my point in using the toolset blocks. Is there anyway to make a block archive and easily copy those settings into the standard editor archive?

thanks again.
Knowing the toolset software as you do any idea do you have any hints as to where the data issue might lie that causes the property type to appear as the default and not all of the ones associated to categories?

#1632317

perhaps another hint to the past is that by mistake the site was originally set up as a multi-site do I don't really understand the implications of that but tried to revert it back to a single.

Another curious thing is why the same block archive displays everything properly on the home page yet only the properties when called from any other page.

#1632863

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

I spent a little time looking at the source code for the custom archives and found a filter we can use to force which post types are included in the category archive, and I tested it on my local copy of the site and it seems to work okay.

So you should be able to go ahead and continue with the custom archive designed with Blocks assigned to the category archive and then add the following code snippet to make sure the archive includes both posts and property post types (and you can add others if needed).

add_filter( 'wpv_filter_object_settings_for_fake_url_query_filters', 'ts_fix_archive_post_types', 1 );
function ts_fix_archive_post_types( $wpa_settings ){

    if ( is_archive() && is_category() ){
        $wpa_settings['post_type'] = array('post','property');
    }
    return $wpa_settings;
}

You can add the code at Toolset > Settings > Custom Code.

That should fix the issue originally reported about which post types are included in the archive.