$args = array( 'posts_per_page' => 6 , 'offset' => 0 , 'meta_query' => array( 'relation' => 'OR' , array( 'key' => 'placing' , 'value' => 'nn' ) , array( 'key' => 'category_id' , 'value' => $cat->term_id ) ) ); $myposts = get_posts($args); And if so, should it be term_id or category_id? … [Read more...] about Use not custom fields in get_posts() meta_query?
Get_terms meta_query
How to use germ_terms() with meta_query for ACF Taxonomy field?
'meta_query' => array( array( 'key' => 'Topic', 'value' => '422', ) ) 'meta_query' => array( array( 'key' => 'Topic', 'value' => 422, ) ) FYI, my “Topic” Taxonomy ACF field “Return Value” is set to “Term ID”, which is why I attempted passing ‘422’. … [Read more...] about How to use germ_terms() with meta_query for ACF Taxonomy field?
How to get_terms() only of terms matching an ACF meta value?
// Pick a focus tag (choose from 'Tags' ACF Checkbox values in the Organisation field) $tag_section = "Publishing"; // First, get all organisation terms $organisations = get_terms( 'company' ); // Initialise array we will use to store only matching organisations $orgs_filtered = array(); // Make an array with only IDs of organisations with a matching tag foreach ($organisations as $organisation) { // Construct prefixed object ref for this organisation $org_id_prefixed = 'company_'. $organisation->term_id; // If the intended value matches the target value if(in_array($tag_section, get_field('tags', $org_id_prefixed))){ // add its term ID to our array - use this array to feed a WP_Query or similar array_push($orgs_filtered, $organisation->term_id); } } ... But this only gives me an array of the IDs of matching terms - not an array **of the terms* themselves. … [Read more...] about How to get_terms() only of terms matching an ACF meta value?
get_terms() but with additional dimensions?
"format" taxonomy term, with name values including "viewpoint". "company" taxonomy terms, which themselves have an ACF Checkbox field, "tags", one of whose values is "Publishing". I want to get only the "company" terms which have a "tags" value of "Publishing" - but I am only interested in getting those companies which have associated "article" posts that also have taxonomy "format" values of "viewpoint" or beneath. … [Read more...] about get_terms() but with additional dimensions?
Order 2 meta_queries differently in WP_Query?
<?php $sticky = get_option( 'sticky_posts' ); $term = get_queried_object(); /* Query sticky posts */ $the_query = new WP_Query( array( 'post__in' => $sticky, 'ignore_sticky_posts' => 1, 'posts_per_page' => 5, 'post_type' => 'ads', 'tax_query' => array( //Get posts by term slug 'relation' => 'OR', array ( 'taxonomy' => 'ad_cat', 'field' => 'slug', 'terms' => $term->slug, ) ), 'meta_query' => array( //Get posts with custom field key 'cc_aff_stick_top' 'relation' => 'OR', 'is_aff' => array( 'key' => 'cc_aff_stick_top', 'compare' => 'EXISTS', ), //Get posts without key 'is_not_aff' => array( 'key' => 'cc_aff_stick_top', 'compare' => 'NOT EXISTS', ), ), //Order by CF cc_aff_stick_top and otherwise by date 'orderby' => array( 'meta_value_num' => 'ASC', 'date' => 'DESC' ), ) ); // The Loop if ( $the_query->have_posts() ) { … [Read more...] about Order 2 meta_queries differently in WP_Query?