I have a select field created with custom field . Field contains a list of numbers from 1 to 10 .
How could do to make the post an ORDER BY query this select?
"orden" is the field select type
Maybe the problem is because the field select is a string?
$args = array(
'post_type' => 'directivo',
'orderby' => 'orden',
'order' => 'ASC',
'showposts' => -1,
'meta_query' => array(
array(
'key' => 'principal_o_suplente',
'value' => 'principal',
'compare' => '=='
),
array(
'key' => 'empresarios_o_',
'value' => 'gobiernos',
'compare' => '=='
)
)
);
Related
i want to make a filter, where i can list employees
however the employees are from post type employees (example) and their contracts are made in child post type called contracts ( example ) so i have made this code but i can't take all info that i need
$args = array( 'post_type' => array( 'employees', 'contracts'),
'posts_per_page' => -1,
'paged' => $paged,
'orderby'=>'title',
'order'=> $order,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'wpcf-podruznici',
'value' => $podruznici,
'type' => 'CHAR',
'compare' => '='
),
array(
'key' => 'wpcf-direkcija_podruznica',
'value' => $podruznici,
'type' => 'CHAR',
'compare' => '='
),
array(
'key' => 'wpcf-opredeneno_neopredeleno_vraboten',
'value' => $dogovor,
'type' => 'CHAR',
'compare' => '='
)
)
this array here
array(
'key' => 'wpcf-opredeneno_neopredeleno_vraboten',
'value' => $dogovor,
'type' => 'CHAR',
'compare' => '='
)
is from the post type contracts
so if in the filter i choose full time or part time i can only list the employees name and it does not give me the other data..
i hope it makes sense
I am trying to fetch the result if keyword, category and meta value is not empty. I mean to say that if the keyword is test and city is Mumbai and category is pet then show existing results that come in these parameters. Now I am getting all the results which have in other categories too.I have two inputs , one for keyword, second for City, zip code and third one for categories drop down.
Any suggestions would be greatly appreciated.
Expected result should be keyword,city under selected category.
$arg = array(
'post_type' => 'post',
'posts_per_page' => 10,
's' => $keyword,
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' =>$cats
)
),
'meta_query' => array(
array( 'key' => 'city', 'value' => $query_city, 'compare' => 'LIKE' ),
array( 'key' => 'country', 'value' => $query_city, 'compare' => 'LIKE' ),
array( 'key' => 'postalcode', 'value' => $query_city, 'compare' => 'LIKE' ),
'relation' => 'OR'),
);
$query = new WP_Query( $arg );
If I understand you right, using 'relation' => 'AND' instead 'relation' => 'OR' should solve your issue.
I would like to know how to compare a date coming as custom field with the current date in a custom loop. I have following script, but it does not work...
enter$args = array(
'post_type' => 'books',
'meta_key'=>'course_date',//the format comes like this Ydm
'meta_value'=> date('d.m.Y'),
'meta_compare'=> '<'
);
My goal is to show all books with when the date is > then the current date. If the current date is > then the related post must be hidden.
Use this Query to get past event list ( 'compare' => '<') and get future events ( 'compare' => '>=')
$event_args = array(
'post_type' => 'books',
'meta_query' => array(
array(
'key' => 'course_date',
'value' => date('Ymd'),
'type' => 'DATE',
'compare' => '<'
)
),
'paged' =>$page,
'meta_key' => 'course_date',
'orderby' => 'meta_value',
'order' => 'ASC',
);
Hi in my post_type=shop i have 2 meta keys and array of values
Custom fields
Name Values
cu_status pending,processing,completed
cu_date 12-Jan-2016 , 13-Jan-2016, ...... any date in the same format date("d-M-Y")
Now i need to loop through all posts with cu_status =pending,processing and cu_date is between 12-Jan-2016 to 13-Apr-2016
What will the query ?
Iam very confused . For to get all post with status pending,processing I know the query
$args = array(
'post_type' => 'shop',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'cu_status',
'value' => array('pending','processing'),
'compare' => 'IN',
)
),
'posts_per_page' => -1
);
Pleases help to complete the query .
You need to use the relation operator e.g.
$args = array(
'post_type' => 'shop',
'post_status' => 'publish',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'cu_status',
'value' => array('pending','processing'),
'compare' => 'IN',
) ,
array(
'key' => 'cu_date',
'value' => array($start, $end),
'compare' => 'BETWEEN',
'type' => 'DATE'
)
),
'posts_per_page' => -1
);
Also use the compare=>BETWEEN for getting the difference in 2 dates.
You may need to tweak the code a bit as I have not tested it.
I am trying to pull custom post type with field value set as 'No' or not set (older posts for which this custom field is not set). The code i am using for query args is:
$args = array_merge( $wp_query->query_vars, array( 'post_type' => 'com', 'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'ct_Featured_C_radio_3292',
'value' => 'No',
'compare' => 'LIKE'
),
array(
'key' => 'ct_Featured_C_radio_3292',
'value' => array(''),
'compare' => 'LIKE'
)
)));
But this meta query only pulls posts with value set as 'No' and not with posts with empty values. Please advice on how to write the meta query so all posts with No and empty values can be pulled.
"NOT EXISTS" checks will include meta_keys that don't exist.
$args = array_merge( $wp_query->query_vars, array( 'post_type' => 'com', 'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'ct_Featured_C_radio_3292',
'value' => 'No',
'compare' => 'LIKE'
),
array(
'key' => 'ct_Featured_C_radio_3292',
'compare' => 'NOT EXISTS'
)
)));
Try This
http://codex.wordpress.org/Class_Reference/WP_Meta_Query
This is related to meta Query