How to properly escape values in meta query

The problem is that you’ve interpreted wpdb::esc_like as a literal copy paste, and not a direction, and used it as a static function, when it is not a static function. Good: global $wpdb; $foo = $wpdb->esc_like( $bar ); Bad: $foo = wpdb::esc_like( $bar ); Other things to note: The & in &$wp_query ) is a … Read more

Need to search a custom field (ingredients, one long string per post), but want it to allow phrases/non-exact matches

You could break apart the search-string into an array and add each word to it’s own meta-query $search_query = ‘strawberries and cream’; $search_query_array = explode(‘ ‘, $search_query); // turn search query string into array of words $stop_words = [‘and’,’or’,’that’,’have’,’with’,’this’]; if ( ! empty( $search_query_array ) ) { foreach( $search_query_array as $index ) { // remove … Read more

meta_query where the meta value is not the post title

I found a solution that works (thanks Steve), hopefully somebody will find this useful in the future $sql = “SELECT p.ID FROM wp_posts AS p WHERE post_parent = $post->ID AND post_type=”post_type” AND ID IN ( SELECT post_id FROM wp_postmeta AS pm WHERE pm.meta_key = ‘my_acf_key’ AND pm.meta_value = p.post_title );”; $idList = $wpdb->get_col( $sql );

get_terms_args ordering by meta key not working

After a lot of searching and tests… Finally I’ve found a solution. Instead using get_terms_args filter, I’ve changed to parse_term_query action. My resulting code looks this way now: add_action(“parse_term_query”, “MyTheme_ParseTermQuery”, PHP_INT_MAX, 1); function MyTheme_ParseTermQuery(&$query) { $taxonomy = $query->query_vars[‘taxonomy’][0]; if($taxonomy == “edition”){ $query->query_vars[‘order’] = “ASC”; $query->query_vars[‘orderby’] = “meta_value_num”; $query->query_vars[‘meta_query’] = [[ ‘key’ => “_edition”, ‘type’ => … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)