Query meta data in taxonomony using plugin Advanced custom fields - wordpress

I want to run a query in wordpress to find all local services posts in a taxonomy called local area by the meta data. I have created a custom field using the advanced custom field plugin with the field name as area_code. I also have a drop down select box with service types.
<?php
$args = array(
'post_type' => 'local_service',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'or',
array(
'taxonomy' => 'service_type',
'field' => 'name',
'terms' => array( $catagory ),
),
array(
'taxonomy' => 'local_area',
'meta_key' => 'area_code',
'meta_value' => $ons_code,
'meta_compare' => '=',
),
),
);
$loop = new WP_Query( $args );
?>

Related

How to show all custom post from custom taxonomy?

I have a custom post called item and custom taxonomy under this custom post called item_category
Now, I want to get all posts based on this custom taxonomy.
To do that, I have this URL of custom taxonomy:
http://localhost/mysite/item_category/event/
Here, item_cateogry is the custom taxonomy and event is the term of this taxonomy.
So, my code is below but not showing anything.
$queried_object = get_queried_object();
$current_category_name = $queried_object->slug; // will print the `event`
$items = new WP_Query(array(
'post_type' => 'item',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => $current_category_name,
'field' => 'slug',
),
),
));
I have found the issues:
Here is the right code:
$items = new WP_Query(array(
'post_type' => 'item',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'item_category',
'field' => 'slug',
'terms' => $current_category_name
),
)
));

how to call optiontree taxonomy select

I ask for help to solve my problem, I use the option-tree framework for displaying custom posts from specific categories, I have this code:
<?php
global $product;
$category_product1 = ot_get_option( 'homepage-slider-cat1' );
$args = array(
'post_type' => 'product',
'numberposts' => 18,
'post_status' => 'publish',
'category' => $category_product1,
'include_children' => true
);
?>
with this post code specific category does not appear.
Please help me
Have you tried the Tax_query as a query parameter? This way you can query on taxonomies.
'tax_query' => array(
array(
'taxonomy' => 'people',
'field' => 'slug',
'terms' => 'bob',
),
),
https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

Hide custom taxonomy posts from Recent posts

I have some custom taxonomy in my WordPress site, but I want to hide a custom taxonomy post from my Recent posts. I have this code:
$c1 = array(
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'quality',
'field' => 'id',
'terms' => 123,
))
);
$c2 = array(
'post_status' => 'publish',
'post__not_in' => $c1,
'posts_per_page' => 10,
);
$recent = new WP_Query($c2);
while ($recent->have_posts()) : $recent->the_post();
But unfortunately it doesn't work. How should I do this?

Wordpress - display posts from a specific custom taxonomy and a certain tag

I need a tax_query that assigned to specific custom category and tags.
Below query showing all products but I need the products to a particular category.
Here tag="sale", category="look"
$args = array(
'post_type' => 'product',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'look' ),
),
array(
'taxonomy' => 'product_tag',
'field' => 'slug',
'terms' => 'sale',
),
),
);
$query = new WP_Query( $args );
You can simply use this
$new = new WP_Query('category_name=look&tag=sale');
try to use something like this
$args = array(
'posts_per_page' => 5,
'post_type' => array('videos','image','audio'),
'category_name' => 'look',
'tag'=>'sale'
);
$loop = new WP_Query( $args );

Wordpress query not filtering by taxonomy when specifying a slug

I have a custom post type called news. Inside that I have two custom taxonomies called press-releases and media-coverage. When I query for multiple posts with this query:
$args = array(
'post_type' => 'news',
'news_type' => 'press-releases',
'posts_per_page' => 15,
'paged' => $json_api->query->page,
);
$query = new WP_Query($args);
It only gets news posts categorized as press-releases like I want. But if I specify a slug that exists in media-coverage it returns that post even though I have the press-releases taxonomy specified. Example:
$args = array(
'name' => $slug,
'post_type' => 'news',
'news_type' => 'press-releases',
'posts_per_page' => 1,
);
You may try this
$args = array(
'post_type' => 'news',
'name' => '$slug,
'posts_per_page' => 1,
'tax_query' => array(
array(
'taxonomy' => 'news_type',
'field' => 'slug',
'terms' => 'press-releases'
)
)
);

Resources