Hot answers tagged

4

As @Howdy_McGee suggested and I made a quick test. Removing key do the trick so you can just remove the key and add compare LIKE if you do not want exact match. Example:- $posts = new WP_Query(array( 'meta_query' => array( array( 'value' => 'meta_value' ) ) )); This will produce the SQL like WHERE 1=1 AND ( ...


2

I found the problem and also fixed a bug in the regex. Final code: 'meta_query' => array( array( 'key' => 'my_meta_field', 'value' => "(^|\n|\r\n)99999($|\n|\r\n)", 'compare' => 'REGEXP', ), ), The problem here was Wordpress was adding extra backslashes on the special characters. By wrapping the expression in ...


1

Q1 Yes, you can store serialized arrays as a single meta key, eg: update_post_meta( $post_id, 'my_items', array( 1, 2, 3, 4 ); Furthermore, you can store multiple values against a single meta key, eg: add_post_meta( $post_id, 'my_items', 1 ); add_post_meta( $post_id, 'my_items', 2 ); The latter is preferred because meta queries can be more efficiently ...


1

After some research on wp codex I found my solution. Here I have to change birth_date format during save. I saved value like yy-mm-dd this format and changed my meta_query Here is the code $studentdata = get_users( array( 'meta_query'=> array( array( ...


1

This $_GET['variable'] is an array, as per your URL query string ?variable[]=value1&variable[]=value2, $_GET['variable'][0] and $_GET['variable'][1] should return those 2 key values Edit - after the discussion - making it dynamic $meta_query = array(); if ( ! empty( $_GET["variable"] ) ) { if ( is_array( $_GET["variable"] ) ) { $meta_query['...


1

The way you are trying to do it is probably the wrong way. WP_Query does not have any build in feature to subtract the values from two custom fields and then returning (or ordering) posts according to the value of the subtraction from the two fields. You can probably filter the generated SQL via the posts_clauses filter or the relevant single clauses ...



Only top voted, non community-wiki answers of a minimum length are eligible