kcmau
Forum Replies Created
-
Forum: Plugins
In reply to: [Hide Posts] WP_Query meta_key being changed by WHPGlad to help. Cheers!
Forum: Plugins
In reply to: [Hide Posts] WP_Query meta_key being changed by WHPUPDATE
It seems WHP may be applied to all post types regardless of the chosen post types setting. After a little investigation I believe I may have found a bug and I think it may be due to a missing set of brackets in whp-hide-posts/inc/class-post-hide.php on line 100 in the “exclude_posts” function.
if ( ! is_admin() || ( is_admin() && wp_doing_ajax() ) && ...I believe this should be …
if ( (! is_admin() || ( is_admin() && wp_doing_ajax() ) ) && ...Without the extra brackets just the !is_admin() is enough for the whole condition to be true whenever you are not an administrator. Adding the extra brackets seems to resolve my issue but I have not thoroughly tested the change.
Please check and confirm?
Regards,
Pete- This reply was modified 4 years, 1 month ago by kcmau.
Forum: Plugins
In reply to: [Hide Posts] WordPress search causing database errorHi Martin,
I’ve found the issue! We are using the Advanced Custom Fields plugin and I’ve found the code from Adam Balée in our theme’s function.php file that enables searching of custom fields without the need for another plugin.
I’ve fixed it using a table alias for the postmeta table in Adam’s code. Here’s the modified code:
function cf_search_join( $join ) { global $wpdb; if ( is_search() ) { $join .=' LEFT JOIN '.$wpdb->postmeta. ' pm ON '. $wpdb->posts . '.ID = pm.post_id '; } return $join; } add_filter('posts_join', 'cf_search_join' ); function cf_search_where( $where ) { global $pagenow, $wpdb; if ( is_search() ) { $where = preg_replace( "/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/", "(".$wpdb->posts.".post_title LIKE $1) OR (pm.meta_value LIKE $1)", $where ); } return $where; } add_filter( 'posts_where', 'cf_search_where' );Of course the cf_search_distinct function does not need any changes as it does not contain any references postmeta.
This gives me the advanced search capability and WHP is still functioning as expected regular posts and custom post types.
It maybe worth considering using table a table alias for postmeta in WHP to avoid any potential conflicts? I imagine we wouldn’t be the only ones using this code.
I hope this helps someone who may be having a similar issue.
Thanks again for setting me on the right path.
Kind Regards,
PeteForum: Plugins
In reply to: [Hide Posts] WordPress search causing database errorHi Martin,
It’s a custom theme we had made and updated over the years.
Ok, I just tried TwentyTwenty and it disappears. It has to be something in our theme that is clashing with WHP right?
Doh, why didn’t I think to try another theme first!
I’ll leave the thread open for now and report back what I find.
Thank you! You have been most helpful.
Regards,
Pete