Skip Navigation

[Resuelto] CPT terms not returned in search results

This support ticket is created hace 5 años, 2 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Etiquetado: 

Este tema contiene 8 respuestas, tiene 2 mensajes.

Última actualización por Beda hace 5 años, 2 meses.

Asistido por: Beda.

Autor
Mensajes
#1334069

I am trying to: Get our "Glossary Terms" to display in search results

Link to a page where the issue can be seen: enlace oculto

I expected to see: One result (enlace oculto)

Instead, I got: Nothing.

I have verified and publicly_queryable is checked in the CPT settings.

Please advise!

**SEE DEBUG IN PREVIOUS POST**

#1334113

That search seems to query posts, pages, and products.
Consequently, "Glossaries" (glossary custom posts) won't appear in the results.

Could I see the backend, where you create the Post type and the eventual search archive?

You do not seem to use Toolset Views for the archive, so it must be a custom or other plugins archive.
Note that the WordPress native Search archive which seems to be used and customized here, is not supporting custom posts out of the box, they need to be added:
enlace oculto
You could do that in Toolset Views archives, or with custom code, if that is the case.

I enabled private reply forms so the access could be shared privately.

#1339483

Why would the archive page be returned in a search query?
Archives are no pages, they are exactly that: archives. Just as search templates, taxonomy archives or post archives.
They won't be results in a search, as they are basically a search result.

In either way - I can not help with this, because the search/display seems 100% custom code work. We can help to build this in Toolset (Views), but not with Custom Code.
For help related to Custom Code, the Certified Contractors could be of help: https://toolset.com/contractors/

Please let me know if you want to use Toolset Views for building the query and results, with which we can help.

#1340235

Hey Beda,

Thanks for the follow-up.

After digging some more I understand this is the default behavior in WordPress, I never really paid that much attention to the search results before and it's the first time I'm building such a comprehensive search experience, so this is a bit new to me. I believe I've read about ways to include the archives in search results so I'll have to check this out.

I understand you can't help with custom code but could you just tell me why the proper URL isn't returned by the WP function "the_permalink();"? This is what's used to return the post URL in the search result.

Thanks again for your help!

#1340295

No, that should not be posssible (ref: https://wordpress.stackexchange.com/questions/203872/make-archive-page-show-up-in-search-results)

What you can do is search an archive, but not show an archive as a result in another search.

You can create that with a few clicks in Toolset Views, both for custom searches and archives.
Please let me know if you want to build this with Toolset (which is made for such tasks). I can help with detailed steps.

Related to the_permalink, that method (https://codex.wordpress.org/Function_Reference/the_permalink) displays the URL for the permalink to the post currently being processed in The Loop.
This is the loop: https://codex.wordpress.org/The_Loop
So this can be one post (single) or many posts.
The the_permalink would - depending on template/items found, return either data of the one post or of the several posts, if it's an archive, for example.
I understand you get 3 instead of one result from the permalink which should mean, there are 3 results in your query results.
It could not output more than one if there would be just one post (or just one post of a kind, so to say).
What is possible, maybe you have those posts saved with the precise exact post date? This can cause random issues like dupli- and quantuplicated posts in results

I can however not analyze the entire code you provided, it is a whole setup of a custom template - we could help with Toolset API related snippets, that enhance Toolset, but not with code that completely "replaces" the Plugin's core functions

For this, we suggest the contractors from this list: https://toolset.com/contractors/.

Thank you for understanding!

#1343493

Hey Beda,

Thanks again for the detailed reply.

The function the_permalink() is indeed used inside The Loop.

I tried to use get_post_permalink(get_the_ID()) instead as it seemed it was more appropriate to retrieve Custom Post Types permalink than the_permalink according to the Codex (https://developer.wordpress.org/reference/functions/get_post_permalink/)

I think you misunderstood what I explained though. The 3 results are all legitimate. There's no duplicate or funky content.

What I'm referring to is the fact the permalink for these items uses the default WP permalinks structure "%post_category/%year/%month%/%day%/%post-title%".

So we have "/uncategorized/2019/09/12/flat-embroidery/" in the search results that redirects to "/how-its-made/customization/flat-embroidery/".

I'd like to avoid the redirection by returning the correct link right-away. Most of the ressources I found explain that this is set during the CPT creation or they suggest using a plugin. I'm pretty sure Toolset creates the CPT appropriately and rewriting works or we would not have a pretty link.

I'm just unsure at this point why the_permalink() uses the default wp permalinks structure instead of the rewritten url for our CPTs.

#1343695

In the Post Type settings are you allowing WordPress rewrites?

The best test here is to create a new Custom Post Type using enlace oculto and see if the same happens there.

In Toolset types you can enable or disable the rewriting, in the post type edit screen

The URL you show me looks not like a Custom Post Type URL but like a either hierarchical post type, or a manipulated (with custom code) URL structure.
I am not sure about the structure you use or code involved.

Also, the the_permalink will return the POST URL. Not the Term archive URL.

I am not sure why you try to customize the website wit hCustom PHP code using Toolset
Toolset is intended and made to avoid Custom Code, and provides methods to make all this in the backend as Archive or Views.

We can not help with custom Coding, unfortunately. This includes explanation of the WordPress API. I would suggest asking in the WordPress Forum, if you need help with this.
Toolset support could help with Toolset Plugins or API, which here is not used.

For links to archives or terms you could use get_term_link, eventually.
Thera is no single "term" post, so the "post" data won't work on terms, however you can of course link to single posts, within term archives, that works then with the_permalink.

I apologize that I cannot be of further assistance with this, as it does not involve Toolset aspects.

#1344327

Hello Beda,

Yes the rewrites are enabled and we are using a custom URL format "/how-its-made/customization" with a custom archive slug "how-its-made/customization".

This makes it so that the archive sits here: enlace oculto
... and every customization term sits there: enlace oculto

I am not trying to customize the site with both custom PHP and toolset, I'm just in a transition process and I can't break everything.

I'm taking steps toward migrating all custom code into toolset, I just haven't gotten to the search page yet because... well it works pretty well (a part from this URL thing with our newly created CPT) and as the adage goes, don't fix what's not broken.

Thank you nonetheless for the suggestions, I'll have to dig deeper to understand what's going on.

We can close this ticket for now!

#1344775

This is strange. You mention this happens only wit the Toolset Types created Post Type?
Could you try this tool enlace oculto, create an exact same post type (with another name) and replicate the same Archive scenario to see if that happens as well with this post type?

In Toolset, you can rewrite Post Type Permalinks, when editing the Post Type.
You can either use Rewrite > Use the normal WordPress URL logic or Rewrite > Use a custom URL format.

When you do that, the posts and archive will listen to the rewritten URL

With Taxonomies you can do the same, and again, it will then respond to the rewrite only (in taxonomy archive and post terms)

I see no issue with the rewriting, it must be due to the code, I assume, because when creating this with Toolset, it works as expected.
You can try that within 5 minutes, by temporarily disabling your custom template and use archive.php default template of for example Twenty Nineteen Theme.
Then create any WordPress Archive you want in Toolset > WordPress Archives.
That will produce a new archive for the terms or posts you choose, and respond to the exact query you set, even if those are rewritten.