Comments (13)
Oh, derp! That does it. Thank you!
from the-seo-framework.
Thank you for the code snippet, I had to add this to my site as I have a very large custom post type database, and with this plugin adding the exclude_local_search
meta query to all queries, was adding anywhere from 2-5 seconds of extra load time on every page load
from the-seo-framework.
Hi NC Jones,
As I'm going to remove the Search class, here's a reference link to what this issue is about:
<search.class active lines of code>
Some information:
The negative search, as shown below, is added to exclude posts that contain that value:
array(
'key' => 'exclude_local_search', // Search for this key.
'value' => '1', // It being 1, or positive (true).
'type' => 'CHAR', // As a CHAR, it's serialized as such in the database.
'compare' => 'NOT EXISTS', // It must not exist, or be false.
'relation' => 'AND', // Continue default search behavior.
),
This code has been introduced in version 2.7.0 of The SEO Framework. The previous way of handling this was injecting and filtering all posts (could be thousands) as a search query happens. This was inefficient.
The issue
If I'm not mistaken, this is the issue at hand:
- On your installation, search results return empty when The SEO Framework 2.7.0 is active.
I browsed through your Divi child theme, and I saw multiple loops being loaded and edited.
As I'm not a theme developer, I took a peek at another theme (i.e. Storefront by WooThemes) and I saw that they simply use:
get_template_part( 'loop' );
I believe there's a lot of complexity going on in your Search Template file. Could you see if excluding some parts of "extra" code to see if the search query acts as it should?
If the concerned code is found, could you share it? This way I can determine where this issue is located.
Cheers!
P.S. take a peek at the Ternary Operator for your $_GET
variable setting :).
Also, I found a bug here (mixed variables).
from the-seo-framework.
Yes, I'll certainly take a look and try testing a simpler loop. I had been trying about 10 different examples I'd found of custom post type searchs to get it to return relevant posts, so no surprise if I scrambled something up somewhere. I'll cut it down and test on my dev and get back to you.
from the-seo-framework.
Hi NC Jones,
I believe this is what you're looking for:
https://gist.githubusercontent.com/galengidman/8b84770a2dcc9abb8bfe/raw/9dae519b202b4ec853bdca8d1689d23f61571b28/search.php
From: https://galengidman.com/2014/06/09/custom-post-type-search-results-templates-in-wordpress/
Best of luck!
Edited code from first link (preventing PHP warnings)
<?php
// store the post type from the URL string
$post_type = ! empty( $_GET['post_type'] ) ? $_GET['post_type'] : '';
// check to see if there was a post type in the
// URL string and if a results template for that
// post type actually exists
if ( 'courses' === $post_type && locate_template( 'search-courses.php' ) ) {
// if so, load that template
get_template_part( 'search', 'courses' );
// and then exit out
exit;
}
?>
<!-- default search results here -->
On the post type search template, you should simply edit the WordPress query.
Like so:
add_action( 'pre_get_posts', 'my_search_query_edit' );
function my_search_query_edit( $query ) {
$query->set('post_type', 'courses' );
}
And then simply output the search page as on search.php
, without other alterations.
EDIT: Adjusted code example towards your template.
from the-seo-framework.
Thanks again for you input @sybrew ! The post you linked to was definitely in my reference material when trying to build this as I scoured many cpt search implementations. The tricky part here was for search-courses.php I have have to be able to force some things into the query if specified, like taxonomy and meta key + value.
But ultimately I think that shouldn't have any effect on search.php results, so now that I've finally had a chance to removed the explode piece and edited the search.php so that it's only checking and redirecting if 'course' === $post_type and not modifying the query otherwise, and I still get 0 results when the SEO Framework is enabled.
So this implementation is up on my dev site now which you can see @ https://multidev.eos.ncsu.edu/ncjones4/?s=shingo Where again, I've dumped the wp_query to try and see what going on. I will leave the SEO Framework active right now to give you a chance to see, but the only major difference I see it the 'exclude_local_search key in the meta_query field. When SEO Framework is not active I get two results for that search term.
from the-seo-framework.
Hi NC Jones,
When you add the following code snippet to your theme's functions.php file, does the search results output work again?
function_exists( 'the_seo_framework' ) and remove_action( 'pre_get_posts', array( the_seo_framework(), 'adjust_search_filter' ), 9999 );
I'm curious as of if the search adjustment of mine is the actual cause or not. Cheers!
from the-seo-framework.
@sybrew Have added that to the theme's functions.php and getting results now with SEO Framework active, can see here https://multidev.eos.ncsu.edu/ncjones4/?s=shingo. Also the courses custom post type search returns results with that implemented as well.
This was sort of my first impulse, to remove that tiny bit via theme's functions.php, but again, I couldn't figure out why it seems to think the 'exclude_local_search' is true on all the content even though it's not set on anything, custom post types or otherwise.
So I think I can push the remove_action bit to production to get SEO Framework reactivated there and maintain the other functionality, but happy to continue testing any suggestions you have to further track down the issue.
from the-seo-framework.
Hi NC Jones,
I dug into your query dumps, and I found the following.
The working query is:
SELECT SQL_CALC_FOUND_ROWS wp_17_posts.ID FROM wp_17_posts WHERE 1=1 AND (((wp_17_posts.post_title LIKE '%shingo%') OR (wp_17_posts.post_excerpt LIKE '%shingo%') OR (wp_17_posts.post_content LIKE '%shingo%'))) AND (wp_17_posts.post_password = '') AND wp_17_posts.post_type IN ('post', 'page', 'attachment', 'courses', 'staff', 'project', 'tribe_venue', 'tribe_events') AND (wp_17_posts.post_status = 'publish' OR wp_17_posts.post_status = 'acf-disabled') ORDER BY wp_17_posts.post_title LIKE '%shingo%' DESC, wp_17_posts.post_date DESC LIMIT 0, 5
The non-working query (with the meta query adjustment) is:
SELECT SQL_CALC_FOUND_ROWS DISTINCT wp_17_posts.ID FROM wp_17_posts LEFT JOIN wp_17_postmeta ON (wp_17_posts.ID = wp_17_postmeta.post_id AND wp_17_postmeta.meta_key = 'exclude_local_search' ) LEFT JOIN wp_17_postmeta ON wp_17_posts.ID = wp_17_postmeta.post_id WHERE 1=1 AND (((wp_17_posts.post_title LIKE '%shingo%') OR (wp_17_postmeta.meta_value LIKE '%shingo%') OR (wp_17_posts.post_excerpt LIKE '%shingo%') OR (wp_17_posts.post_content LIKE '%shingo%'))) AND (wp_17_posts.post_password = '') AND ( [request] => SELECT SQL_CALC_FOUND_ROWS wp_17_posts.ID FROM wp_17_posts WHERE 1=1 AND (((wp_17_posts.post_title LIKE '%shingo%') OR (wp_17_posts.post_excerpt LIKE '%shingo%') OR (wp_17_posts.post_content LIKE '%shingo%'))) AND (wp_17_posts.post_password = '') AND wp_17_posts.post_type IN ('post', 'page', 'attachment', 'courses', 'staff', 'project', 'tribe_venue', 'tribe_events') AND (wp_17_posts.post_status = 'publish' OR wp_17_posts.post_status = 'acf-disabled') ORDER BY wp_17_posts.post_title LIKE '%shingo%' DESC, wp_17_posts.post_date DESC LIMIT 0, 5
(
wp_17_postmeta.post_id IS NULL
)
) AND wp_17_posts.post_type IN ('post', 'page', 'attachment', 'courses', 'staff', 'project', 'tribe_venue', 'tribe_events') AND (wp_17_posts.post_status = 'publish' OR wp_17_posts.post_status = 'acf-disabled') GROUP BY wp_17_posts.ID ORDER BY wp_17_posts.post_title LIKE '%shingo%' DESC, wp_17_posts.post_date DESC LIMIT 0, 5
The big difference:
LEFT JOIN wp_17_postmeta ON (wp_17_posts.ID = wp_17_postmeta.post_id AND wp_17_postmeta.meta_key = 'exclude_local_search' )
What's peculiar is that my adjustment definitely asks that it should be "NOT EXISTS", but the output query tries to find "EXISTS" matches here.
The underlying reason still has to be found. But this is definitely a bug; although situational.
from the-seo-framework.
Hi @ndyjones,
I'll attach a small patch (please test 😄) in a moment which I hope should fix this, letting WordPress' WP_Meta_Query figure this out automatically.
Cheers!
from the-seo-framework.
Hi @ndyjones,
I'm closing this issue for now. If you still encounter this issue after using the latest Master version or the 2.8.0 release version, feel free to re-open this issue.
Cheers! 😄
from the-seo-framework.
@sybrew, I tried removing the action the way you described above, but it didn't work. I checked against the current version of the plugin and tried a few different methods, but still couldn't get it working.
In the past, I've only been able to remove actions from classes that have static methods. I tried that here too, but still nothing.
from the-seo-framework.
@jhned you need to run the action removal after init priority 0
, as at that point the action is created.
i.e.:
add_action( 'init', function() {
$tsf = function_exists( 'the_seo_framework' ) ? the_seo_framework() : null;
if ( is_object( $tsf ) )
remove_action( 'pre_get_posts', array( $tsf, 'adjust_search_filter' ), 9999 );
}, 1 ); // note the 1, it's higher than 0 :)
from the-seo-framework.
Related Issues (20)
- Add listeners for default visibility options in quick-edit.
- 5.0 Beta Test. HOT 1
- Add SEO Bar to User list edit
- Set custom namespaces for compatibility files
- Hashtag/pound is removed from theme-color HOT 1
- Typo: "Note: rhe description " on Settings > Homepage > Meta Description HOT 1
- Toggle Sitemap stylesheet header link HOT 1
- Google Tag Manager connection HOT 1
- Sitemap priority setting HOT 1
- Post archive title shows as "No Title - (website name)"
- Site name is not displayed by Google + Schema.org: 'alternateName' is missing HOT 7
- Make archive exclusions work for adjacent post links. HOT 2
- Polylang: Wrong canonical URL for non-default language's homepage HOT 1
- `wp_sitemaps_post_types` vs `the_seo_framework_sitemap_supported_post_types` hook HOT 3
- Add noindex headers to the Core Sitemap
- Add breadcrumb title and hierarchy options HOT 8
- Option to not notify search engines on post update
- Allow setting of custom alternateName(s)
- Opengraph tags are printed with needlessly high priority HOT 1
- Description generator excludes single-letter abbreviations at start.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from the-seo-framework.