Saltar navegación

[Resuelto] Hide archive if no posts exist

This support ticket is created hace 1 año, 10 meses. 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.

Este tema contiene 3 respuestas, tiene 2 mensajes.

Última actualización por Christopher Amirian hace 1 año, 10 meses.

Asistido por: Christopher Amirian.

Autor
Mensajes
#2559031

I am trying to hide a CPT archive when there are no posts posted. Is this possible?

Here is the Archive example: enlace oculto

Thank you!

#2559233

Christopher Amirian
Supporter

Idiomas: Inglés (English )

Hi there,

Archive is a page that shows the list of custom posts.

Now if there is no custom post it will say to item found.

I am not sure what do you mean by HIDE ARCHIVE?

Do you mean if the link is accessed that link throws 404?

I am not sure what you mean.

#2559467

Hi,
Sorry, I wasn't clear. I would like to hide the archive menu item if there are no posts in that archive. It's not a good experience if people click on that to see no posts.
thanks!

#2559913

Christopher Amirian
Supporter

Idiomas: Inglés (English )

Hi there,

Toolset does not have such a feature. That can be achieved by custom development.

The gist of the method will be as follows:

- Check if the post type has any posts or not:

https://stackoverflow.com/questions/4023932/wordpress-query-if-a-custom-post-type-has-any-posts-from-outside-the-loop

- Instead of adding the menu item manually from Appearance > Menus, add it via PHP and use the check above to add the menu or not.

enlace oculto

As this is outside of our support scope you are welcome to hire a developer from the list below if needed:

https://toolset.com/contractors/

Thanks.