Filtering output by two custom fields using posts_where and add_rewrite_rule
Filtering output by two custom fields using posts_where and add_rewrite_rule
Filtering output by two custom fields using posts_where and add_rewrite_rule
I doubt that ever worked by itself. WP_Query operates on posts database table. On the bottom SQL level to make use of post metadata you need to not only say what metadata you are looking for, but also instruct MySQL how metadata table connects to your posts table (JOIN realm). I would attempt to keep … Read more
In general this would make sense at pre_get_posts since you could just express conditions as meta query and let WP figure out SQL. In your specific case this won’t work, since that format is horrible for programmatic comparison. Unless you can change format to something more friendly, you will probably have to write some pretty … Read more
ok folks, i did it anothere way.. here’s how i did it: add_filter( ‘pre_get_posts’, function( $query ) { if( ! is_main_query() || ! is_post_type_archive() || ! $query->get( ‘section’, false ) ) return $query; global $wpdb; $section = $query->get( ‘section’ ); unset( $query->query[‘section’] ); unset( $query->query_vars[‘section’] ); $query->tax_query = false; $query->set( ‘tax_query’, false ); $cateroties = … Read more
Avoid changing menu query with suppress_filters => false
I have finally been able to come up with a solution based on some help from my more MySQL oriented question at Stack Overflow: add_filter( ‘posts_fields’, ‘posts_fields’ ); function posts_fields( $fields ) { if ( ( is_woocommerce() || is_search() ) && ! is_admin() ) { $add = ” , CASE wt.slug WHEN ‘antique’ THEN 1 … Read more
First look how complex is your preg replace. Usually, you may get into errors with that. NODE EXPLANATION ——————————————————————————– / “https://wordpress.stackexchange.com/” ——————————————————————————– \( ‘(‘ ——————————————————————————– \s* whitespace (\n, \r, \t, \f, and ” “) (0 or more times (matching the most amount possible)) ——————————————————————————– post_title ‘post_title’ ——————————————————————————– \s+ whitespace (\n, \r, \t, \f, and ” … Read more
I sort of solved this by using this: function ar6_password_post_filter( $where=”” ) { if (!is_single() && !current_user_can(‘edit_private_posts’) && !is_admin()) { $where .= ” AND post_password = ””; } return $where; } add_filter( ‘posts_where’, ‘ar6_password_post_filter’ ); This allows user roles of administrator and editor to still see the password protected posts on the front end of … Read more
WP_Query’s WHERE updated, but Search Results are not updated
Custom SQL query slows down when using multiple OR … LIKE … in posts_where filter