- This topic has 18 replies, 2 voices, and was last updated 2 years, 11 months ago by
Trevis.
-
AuthorPosts
-
March 31, 2023 at 1:15 pm #2591235
Trevis
Hey GP Team, happy Friday!
I’d like to create a template for the search results page, but only apply it to a custom post type (glossary). Is this possible with GP Elements?
Thanks much!
April 1, 2023 at 5:23 am #2591883David
StaffCustomer SupportHi there,
does the glossary CPT have its own search archive ? Or will the results be a mix of post types ?
April 1, 2023 at 7:04 am #2591981Trevis
Hi David, I am using the Ivory Search plugin, which will return only results for the glossary CPT, which is the product of the Glossary for WP Pro plugin. You can see what I have going in the link I’ve privately included.
April 1, 2023 at 7:29 am #2592021David
StaffCustomer SupportOk, so in the Block Element, you should see a Glossary Archive in the display rules ?
If so can you try using that for Content Template.April 1, 2023 at 9:01 am #2592175Trevis
That’s what I was thinking too, so I created a template for the Glossary Archive, but the layout and styles are not applied. That archive can be seen in the link included privately.
April 1, 2023 at 1:48 pm #2592397David
StaffCustomer SupportSo the Glossary list is being output by what looks to be a block from that plugin
wp-block-glossary-by-codeat-list
The Theme can’t change its styles.Is there any other method that plugin can display its posts ?
April 1, 2023 at 2:31 pm #2592433Trevis
To render the glossary terms list, you can use the plugin block, a shortcode, or it renders an archive page for the glossary CPT, as well. I have successfully styled all of those using GP Elements, but can’t target the search results page rendered by the Ivory Search plugin for some reason. I scanned their support feed on WP.org and found this:
The search results page is displayed by the search.php file of the theme that you are using on your site so the plugin doesn’t control how it is displayed but your site theme controls it.
You can customize this developing custom code in the search.php file of your child theme by contacting the theme author or consider hiring a developer to develop it for you.
So, if I target the Search Results page with a GP Element, it’ll work, but it will affect all search results pages. Any way to tell Elements to exclude certain post types or include only a specific post type?
April 2, 2023 at 3:49 am #2592865David
StaffCustomer SupportOk, so there is the
generate_element_displayfilter hook:https://docs.generatepress.com/article/generate_element_display/And with it you could try this:
1. Create your element, and set its display rules to the Search. And make a note of its ID
2. Add this snippet and replace the
100with the element ID, and thepost_typewith your post type:add_filter( 'generate_element_display', function( $display, $element_id ) { if ( 100 === $element_id && is_search() && ! is_post_type_archive( 'post_type' ) ) { $display = false; } return $display; }, 10, 2 );Now on a search page if the post type archive does not match your post type then it should disable it..
Let me know if that works.
April 2, 2023 at 1:46 pm #2593607Trevis
Aha — that did the trick, thank you so much! And thanks for introducing me to that hook, I already see some potential uses for it elsewhere.
Once again, thank you for the assistance and the continued top-tier support!
April 3, 2023 at 3:34 am #2594312David
StaffCustomer SupportGlad to hear that 🙂
April 3, 2023 at 4:34 pm #2595411Trevis
Hi again, I’ve run into a side effect with this element…
The glossary plugin has a field for “hidden” keywords to append to a glossary term which, when searched for, will return the main glossary term it is attached to. For example, I have a glossary term called “An Example” and entered a hidden keyword of “apple”, so when I search for “apple”, it will display the “An Example” entry in the search results, even though the title or content of that term do not include the word “apple.”
This was working as it should, until I applied this element to the search results page for the glossary CPT. Now when I search for “apple”, the search page does not display the results, just a blank area where the results should be. If I search for a word in the title or content of a glossary term, it shows the correct results.
I believe it’s related to the element, because if I disable the element, it functions as it should again, returning the post with the hidden key term. But when I re-activate the element, no luck.
I have the Query Parameters set to “Inherit query from template”, but maybe the element isn’t grabbing the data included in the CPT related to the hidden keywords for some reason?
Sorry if this should go in another thread, I figured the previous communication might be helpful, so added to this one. Let me know if you’d like me to open another.
Thanks!
April 4, 2023 at 4:05 am #2596092David
StaffCustomer SupportSounds like that plugin is filtering the search query and thats happening sometime after the Query Loop block does its thing.
Although we can’t change the Query Loops behaviour at this time, could you find out from the plugin developer so we can factor that in for the future?In the meantime, if you don’t mind testing.
If your replace the GB Query Loop block with the core Query Loop block and set it to Inherit Query from Template.
This is just a test… does that respect those hidden search queries ?If it does then we can take a look at what it’s doing.
Ok, so what to do instead.
It will take a little reworking, but you can build a block element content template instead of a loop template:https://docs.generatepress.com/article/block-element-content-template/
With that you design just the post template which gets hooked into the themes loop. So that should respect whatever that plugin is doing to the query.
Now the content thats outside of the loop such as the search form, that would need to be added using a separate Block Element Hook and hooked in before the main content.
Although its more work, this method won’t change the default loops behaviour.
April 4, 2023 at 8:54 am #2596625Trevis
Man, not sure why I didn’t think of that before reaching out again… The core query loop does respect the hidden terms and now everything functions as it should.
Let me know if you can’t see what’s causing the inconsistency between the core query loop and the GP query loop and I’d be happy to reach out the the dev of the Glossary for WP Pro plugin to find out more about the search filtering sequence and relay that to you.
I’d also be willing to upload the plugin files for you, if that would be helpful.
Again, thank you for your expert guidance and stellar support. I really can’t express the level of appreciation I have for GP products and your team. Y’all are great!
April 5, 2023 at 3:52 am #2597706David
StaffCustomer SupportGood to hear that works, but not so good to hear that the GB block doesn’t.
If you could find out from the plugin developer how they handle the “hidden” search terms and how that is inserted into the query.
In the meantime we’ll do some investigations.
Thanks for your patience and assistance with this.April 5, 2023 at 3:49 pm #2598722Trevis
This is what the developer had to say about it:
“The related terms (it is a custom field of our plugin) are used by our plugin to search inside the page in our code, so they are not used by other plugins or integrations.”
I had forgotten to mention that I am using Ivory Search for the search function of the glossary, so he also wrote this:
“…the native WordPress search feature doesn’t support the related term that we offer. WordPress search just uses the post title, so the issue you are facing it is happening in any theme, so it isn’t a fault of the theme. They are just similar terms, used only for the automatic injection, usually they are used for acronyms or the same term in multiple form. It is an internal feature that isn’t exposed in any list or search.”
Informed him that I am using Ivory Search and apparently it does support the related terms field of his plugin. I don’t really understand why they have it if it isn’t searchable, but I’m glad I accidentally made it do what I was thinking it already did. 🤷♂️😂
Not sure if any of his reply helps you figure anything out and I’ll update here if/when he responds, and here’s a link to their documentation as well: https://docs.codeat.co/glossary/
-
AuthorPosts
- You must be logged in to reply to this topic.