damienlee
Forum Replies Created
-
Hi Sybre
I replied but for some reason it didnt update here so I will paste in my response below:
No, no TSF title or meta are passed to this template at all even though they are set and have worked for me prior to this version using ACF registered taxonomies and post types. That doesn’t mean that’s the cause though but just a consideration.It’s as though TSF is not hooking into the page at all. Is there a built-in function I can call on the page to log what TSF is doing if anything?
I should qualify that, if the archive is unfiltered by a taxonomy it does show the correct title and meta in the page. Its just when its filtered that they all revert to the one post type title regardless of which post type is being viewed.
Cheers Damien
PS…Just been messing with hreflang tags and occured to me that it would be useful as a feature to add this to the sitemap via TSF as a possible future feature option.Thanks Sybre! Sent as requested π
Hi Sybre
Its entirely possible this issue could be caused by something different with ACF registering of post-types and taxonomies. I didnt have this issue when I used Pods to do this task but trusted ACF should be a good option to avoid needing to use pods anymore.
Do you want all post-types and taxonomies?
For reference, all have the api enabled for each type with ACF.
I should also mention that I use Oxygen Builder, but the only difference between when I didnt have an issue and now has been a much later TSF version and using ACF to register the posts-types and taxonomies. I assume its an TSF issue mainly because without it they display correctly. Also the fact that TSF doesnt use the custom title and descriptions I set for my post-types is cause for concernThanks for your response. I don’t think this is the problem. If i disable TSF the page titles show correctly as generated by wordpress without issue. Also, the post-type unfiltered is already the canonical.
Let me clarify with another example:
Post-types: Authors, Books, Publishers
Taxonomy: Genre
In this example, Authors is the first listed post-type created with ACF.
domain.com/authors/ (page title Authors | domain.com)
domain.com/authors/genre/fiction/ (page title Authors | domain.com)
domain.com/books/ (page title Books | domain.com)
domain.com/books/genre/fiction/ (page title Authors | domain.com) <– Should be “Books”
domain.com/Publishers/ (page title Publishers | domain.com)
domain.com/Publishers/genre/fiction/ (page title Authors | domain.com) <– Should be “Publishers”
There are not multiple filters involved, simply one common taxonomy filter. Its as though TSF is mapping to the taxonomy over the post-type and attributing the taxonomy to the first post-type its attached to and returning the page title for that post-type instead of the post-type the archive is actually for. Im starting to think its actually a bug with TSF. That TSF assumes a taxonomy will only be attached to a single post-type and grabs the title this way.
I appreciate your help!Forum: Plugins
In reply to: [WP Search with Algolia] Customise snippet by post typeYep! Guess wordpress.org need to work on escaping their code block better.
Forum: Plugins
In reply to: [WP Search with Algolia] Customise snippet by post typeHi Michael
Yes, looks like wordpress.org removed them, the original I pasted in is correct. Ill post a little bit again and see if it happens again.
Cheers<div class="suggestion-post-attributes"> <span class="suggestion-post-title">data._highlightResult.post_title.value</span> <# if ( data._snippetResult && data._snippetResult['content'] ) { #> <span class="suggestion-post-content">data._snippetResult['content'].value</span> <# } #> </div>Forum: Plugins
In reply to: [WP Search with Algolia] Customise snippet by post typeHi Michael
In regards to errors, it was throwing no errors at all. In order to resolve the issue as the template seemed to be the only part that was causing the issue, I added another condition to allow the script to work still if any field is missing in addition to having a null response. Perhaps you may want to add this in the future as it would likely save a lot of headaches for users and support requests. I have included the change below. It also includes the feature on the link which is probably unnecessary (as what’s the point without the link). However, I included it so I could see what was happening if needed and the link was not there in the Algolia result.
Thanks for your assistance.<script type="text/html" id="tmpl-autocomplete-post-suggestion"> <a class="suggestion-link" href="{{ data.permalink }}" title="{{ data.post_title }}"> <# if ( data.images && data.images.thumbnail ) { #> <img class="suggestion-post-thumbnail" src="{{ data.images.thumbnail.url }}" alt="{{ data.post_title }}"> <# } #> <div class="suggestion-post-attributes"> <span class="suggestion-post-title">data._highlightResult.post_title.value</span> <# if ( data._snippetResult && data._snippetResult['content'] ) { #> <span class="suggestion-post-content">data._snippetResult['content'].value</span> <# } #> </div> <?php do_action( 'algolia_autocomplete_after_hit' ); ?> </a> </script> <script type="text/html" id="tmpl-autocomplete-user-suggestion"> <a class="suggestion-link user-suggestion-link" href="{{ data.posts_url }}" title="{{ data.display_name }}"> <# if ( data.avatar_url ) { #> <img class="suggestion-user-thumbnail" src="{{ data.avatar_url }}" alt="{{ data.display_name }}"> <# } #> <span class="suggestion-post-title">data._highlightResult.display_name.value</span> </a> </script>- This reply was modified 1 year, 10 months ago by damienlee.
Forum: Plugins
In reply to: [WP Search with Algolia] Customise snippet by post typeHi Michael
I went over some of your points. Good pickup on the title, which I have fixed. I have checked the results in the dev console and Algolia is returning all the correct fields as required by the plugin as far as I can see. It’s the plugin that is the source of the issue or my lack of understanding about perhaps a particular field that the plugin requires not to be missing from the index.
Here is the current code I’m using for a post type called “Ingredients” and it works perfectly as long as the thumbnail is in the index. As soon as I remove the thumbnail from the index it ceases to work on the plugin side. That suggests to me that the plugin requires an image field to function, but skips it on the template if the image field is present but is null.// Customize the Algolia attributes for the 'ingredient' post type. add_filter('algolia_post_ingredient_shared_attributes', 'customize_algolia_ingredient_attributes', 10, 2); add_filter('algolia_searchable_post_ingredient_shared_attributes', 'customize_algolia_ingredient_attributes', 10, 2); function customize_algolia_ingredient_attributes(array $attributes, WP_Post $post) { // Ensure only the specified fields are indexed. $attributes = array( 'post_id' => $post->ID, 'post_title' => $post->post_title, 'content' => $post->post_content, 'permalink' => get_permalink($post), 'post_type' => $post->post_type, 'post_type_label' => get_post_type_object($post->post_type)->labels->name, // 'images' => array( // 'thumbnail' => get_the_post_thumbnail_url($post, 'full') // ), ); return $attributes; }
This presents an issue for me as the post needs an image on the site, but I don’t want it to display the image field within search results. I guess my only way to solve this is to put additional conditions in the template based on post_type, though this is a messy approach. I think ideally the plugin should have a fallback if no image field is in the index. If for no other reason than correctly handling such instances where the image field is unavailable.
On a related note, if I disable the content snippet from being included in the results from Algolia it also seems to break the plugin too.There is one staging instance that im presently working on. I have provided for you below what is returned by Algolia when I am not indexing the images.
content: objectID: permalink: post_id: post_title: post_type: post_type_label: record_index: _highlightResult: _snippetResult:Forum: Plugins
In reply to: [WP Search with Algolia] Customise snippet by post typeWhen I say “it will stop providing results at all”, I refer to the specific post type that I removed the images.thumbnail from. I have taken your advice and approached it another way by changing what is indexed in the first place.
In this case, I have used the following to ensure only the information I want is indexed. This has also caused the same issue however. It seems like the plugin expects certain data or it skips the post even if the template itself seems to cater for null values with a condition./** * Customize the Algolia indexed attributes for the 'ingredient' post type. * * @param array $attributes Attributes to be sent to Algolia. * @param WP_Post $post The current post object being indexed. * * @return array Modified array of attributes for Algolia. */ function filter_algolia_post_attributes( $attributes, $post ) { // Check if the current post type is 'ingredient' if ( 'ingredient' === $post->post_type ) { // Define the attributes you want to keep $custom_attributes = [ 'post_id' => $post->ID, 'title' => $post->post_title, 'content' => $post->post_content, 'permalink' => get_permalink( $post ), ]; // Return the custom attributes for the 'ingredient' post type return $custom_attributes; } // Return the original attributes for all other post types return $attributes; } // Add the filters for shared attributes and searchable post shared attributes add_filter( 'algolia_post_shared_attributes', 'filter_algolia_post_attributes', 10, 2 ); add_filter( 'algolia_searchable_post_shared_attributes', 'filter_algolia_post_attributes', 10, 2 );Forum: Plugins
In reply to: [WP Search with Algolia] Customise snippet by post typeNo sorry, I only have space on the current environment for my main staging space. However its very easy to replicate. Just install the plugin and go to Algolia and remove the images.thumbnail attribute from being sent and it will stop providing results at all.
Yes thats true, I need to remove it from the indexing also but I imagine that will have the same impact on getting the results. I would just edit the template but I have several post types and some will show the thumbnail but others not. It didn’t seem efficient to edit the template for every post type with conditions when I can simply choose not to send that data from Algolia for the relevant post types.Forum: Plugins
In reply to: [WP Search with Algolia] Customise snippet by post typeI think I didn’t explain myself well. I’m not sure if I need to edit the template at all.
I was trying to remove things like “images.thumbnail” as a retrieved attribute in the Algolia dashboard. As the template checks to see if there is a valid attribute before displaying that attribute. I assumed this was so I could just stop Algolia from sending an attribute for a given post type and it would not be displayed. See the example below from the template:<# if ( data.images.thumbnail ) { #> <img class="suggestion-post-thumbnail" src="{{ data.images.thumbnail.url }}" alt="{{ data.post_title }}"> <# } #>As you see it checks the images.thumbnail is there before attempting to display it. However, whenever I remove the attribute images.thumbnail in Algolia, the plugin fails to show any of the post types I removed the thumbnail attribute from.
CheersForum: Plugins
In reply to: [Permalink Manager Lite] CPT Articles archive missingSolved! haha
Thanks that helped actually. I cant believe it but for some reason I had a page with the slug “articles” though not sure why. My apologies for this was my error. Though your last suggestion helped me find it. Thanks!Forum: Plugins
In reply to: [Permalink Manager Lite] CPT Articles archive missingThere must be something that touches on archive permalinks in some manner as if i change the post type slug with rewrite rules to “article” rather than “articles” and then rewrite the permalinks in the manager it works. Also if I disable permalink manager it works too.
I had already tried flushing the permalinks as suggested but tried again anyway without luck. I think as it works with “article” rather than the “articles” slug I may just do this for now. Its not what I ideally want but I’m not sure its worth the time to try and find what the conflict is with permalink manager.Forum: Plugins
In reply to: [Relevanssi - A Better Search] S parameter in query & RelevanssiThanks and good to know.
Yes, a normal search template seems to work fine though not quite as snappy as id like, but probably due to the size of the database.
The query im running has only these parameters set:
post_type=product
posts_per_page=4
s=vegan (for example, but this is a dynamic value normally)
Ive also had it output the query vars(if helpful):
array(73) { [“rel”]=> string(5) “vegan” [“error”]=> string(0) “” [“m”]=> string(0) “” [“p”]=> int(0) [“post_parent”]=> string(0) “” [“subpost”]=> string(0) “” [“subpost_id”]=> string(0) “” [“attachment”]=> string(0) “” [“attachment_id”]=> int(0) [“name”]=> string(0) “” [“pagename”]=> string(0) “” [“page_id”]=> int(0) [“second”]=> string(0) “” [“minute”]=> string(0) “” [“hour”]=> string(0) “” [“day”]=> int(0) [“monthnum”]=> int(0) [“year”]=> int(0) [“w”]=> int(0) [“category_name”]=> string(0) “” [“tag”]=> string(0) “” [“cat”]=> string(0) “” [“tag_id”]=> string(0) “” [“author”]=> string(0) “” [“author_name”]=> string(0) “” [“feed”]=> string(0) “” [“tb”]=> string(0) “” [“paged”]=> int(0) [“meta_key”]=> string(0) “” [“meta_value”]=> string(0) “” [“preview”]=> string(0) “” [“s”]=> string(0) “” [“sentence”]=> string(0) “” [“title”]=> string(0) “” [“fields”]=> string(0) “” [“menu_order”]=> string(0) “” [“embed”]=> string(0) “” [“category__in”]=> array(0) { } [“category__not_in”]=> array(0) { } [“category__and”]=> array(0) { } [“post__in”]=> array(0) { } [“post__not_in”]=> array(0) { } [“post_name__in”]=> array(0) { } [“tag__in”]=> array(0) { } [“tag__not_in”]=> array(0) { } [“tag__and”]=> array(0) { } [“tag_slug__in”]=> array(0) { } [“tag_slug__and”]=> array(0) { } [“post_parent__in”]=> array(0) { } [“post_parent__not_in”]=> array(0) { } [“author__in”]=> array(0) { } [“author__not_in”]=> array(0) { } [“search_columns”]=> array(0) { } [“orderby”]=> string(16) “menu_order title” [“order”]=> string(3) “ASC” [“meta_query”]=> array(0) { } [“tax_query”]=> array(2) { [“relation”]=> string(3) “AND” [0]=> array(4) { [“taxonomy”]=> string(18) “product_visibility” [“field”]=> string(16) “term_taxonomy_id” [“terms”]=> array(1) { [0]=> int(7) } [“operator”]=> string(6) “NOT IN” } } [“wc_query”]=> string(13) “product_query” [“posts_per_page”]=> int(4) [“ignore_sticky_posts”]=> bool(false) [“suppress_filters”]=> bool(false) [“cache_results”]=> bool(true) [“update_post_term_cache”]=> bool(true) [“update_menu_item_cache”]=> bool(false) [“lazy_load_term_meta”]=> bool(true) [“update_post_meta_cache”]=> bool(true) [“post_type”]=> string(0) “” [“nopaging”]=> bool(false) [“comments_per_page”]=> string(2) “50” [“no_found_rows”]=> bool(false) [“taxonomy”]=> string(3) “rel” [“term”]=> string(5) “vegan” [“relevanssi”]=> bool(false) } array(55) { [“post_type”]=> string(7) “product” [“posts_per_page”]=> string(1) “4” [“s”]=> string(5) “Vegan” [“error”]=> string(0) “” [“m”]=> string(0) “” [“p”]=> int(0) [“post_parent”]=> string(0) “” [“subpost”]=> string(0) “” [“subpost_id”]=> string(0) “” [“attachment”]=> string(0) “” [“attachment_id”]=> int(0) [“name”]=> string(0) “” [“pagename”]=> string(0) “” [“page_id”]=> int(0) [“second”]=> string(0) “” [“minute”]=> string(0) “” [“hour”]=> string(0) “” [“day”]=> int(0) [“monthnum”]=> int(0) [“year”]=> int(0) [“w”]=> int(0) [“category_name”]=> string(0) “” [“tag”]=> string(0) “” [“cat”]=> string(0) “” [“tag_id”]=> string(0) “” [“author”]=> string(0) “” [“author_name”]=> string(0) “” [“feed”]=> string(0) “” [“tb”]=> string(0) “” [“paged”]=> int(0) [“meta_key”]=> string(0) “” [“meta_value”]=> string(0) “” [“preview”]=> string(0) “” [“sentence”]=> string(0) “” [“title”]=> string(0) “” [“fields”]=> string(0) “” [“menu_order”]=> string(0) “” [“embed”]=> string(0) “” [“category__in”]=> array(0) { } [“category__not_in”]=> array(0) { } [“category__and”]=> array(0) { } [“post__in”]=> array(0) { } [“post__not_in”]=> array(0) { } [“post_name__in”]=> array(0) { } [“tag__in”]=> array(0) { } [“tag__not_in”]=> array(0) { } [“tag__and”]=> array(0) { } [“tag_slug__in”]=> array(0) { } [“tag_slug__and”]=> array(0) { } [“post_parent__in”]=> array(0) { } [“post_parent__not_in”]=> array(0) { } [“author__in”]=> array(0) { } [“author__not_in”]=> array(0) { } [“search_columns”]=> array(0) { } [“relevanssi”]=> bool(false) }Forum: Plugins
In reply to: [Relevanssi - A Better Search] Oxygen Advanced Query missing search resultsIn that case, how do you limit the number of returned results with Relevanssi, and without pagination?
Is there not a simple method to leverage Relevanssi to return results with all of the same function as wp_query while using Relevanssi to replace the search query results? Perhaps i need flexibility Relevanssi is simply not designed for. Though it has been great in past non-oxygen projects where I didnt need to customise the output quite so much.