Using Dynamic multiple attributes With WP_Queryadd_magic_quotes() is not working in wordpressIncorrect posts showing through WP-Query on WooCommerceSetting Tax Query in pre_get_posts still showing products with the wrong taxonomyShow posts from custom taxonomyWordPress & BuddyPress Outputting PHP to pageWordpress: Using post__not_in to exclude custom taxonomy categoryHow to Search posts using LIKE for Category Name in wordpress?WP_Query not ordering by titleAdding Alt Tags To CarouselGet image post by taxonomy/category wordpress
Antonym of "Megalomania"
What is the highest achievable score in Catan
Is it possible to tell if a child will turn into a Hag?
Unknown indication below upper stave
Applications of pure mathematics in operations research
Why does the Rust compiler not optimize code assuming that two mutable references cannot alias?
Prepare a user to perform an action before proceeding to the next step
Is it possible for a particle to decay via gravity?
If the Moon were impacted by a suitably sized meteor, how long would it take to impact the Earth?
Why would anyone ever invest in a cash-only etf?
Should I put my name first, or last in the team members list
What is this kind of symbol meant to be?
Boots or trail runners with reference to blisters?
What is a good example for artistic ND filter applications?
Can machine learning learn a function like finding maximum from a list?
Did Vladimir Lenin have a cat?
My employer is refusing to give me the pay that was advertised after an internal job move
Why are subdominants unstable?
Three Dots in Center Page
Can I attune a Circlet of Human Perfection to my animated skeletons to allow them to blend in and speak?
Why did Windows 95 crash the whole system but newer Windows only crashed programs?
What clothes would flying-people wear?
Does Ubuntu reduce battery life?
Move arrows along a contour
Using Dynamic multiple attributes With WP_Query
add_magic_quotes() is not working in wordpressIncorrect posts showing through WP-Query on WooCommerceSetting Tax Query in pre_get_posts still showing products with the wrong taxonomyShow posts from custom taxonomyWordPress & BuddyPress Outputting PHP to pageWordpress: Using post__not_in to exclude custom taxonomy categoryHow to Search posts using LIKE for Category Name in wordpress?WP_Query not ordering by titleAdding Alt Tags To CarouselGet image post by taxonomy/category wordpress
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a form from where clicks on the attribute and based on that click, I change my query to fetch relevant results
Below Array is generated dynamically based on user selection
Array
(
[tax_query] => Array
(
[0] => Array
(
[taxonomy] => pa_timing
[field] => slug
[terms] => Array
(
[0] => day
)
)
[1] => Array
(
[taxonomy] => pa_size
[fields] => slug
[terms] => Array
(
[0] => s
)
)
)
[post_type] => product
[post_status] => publish
[product_cat] => pads
[posts_per_page] => -1
)
Based on the above array WP_Query generated
SELECT vsrc_posts.* FROM vsrc_posts LEFT JOIN vsrc_term_relationships ON (vsrc_posts.ID = vsrc_term_relationships.object_id) LEFT JOIN vsrc_term_relationships AS tt1 ON (vsrc_posts.ID = tt1.object_id) LEFT JOIN vsrc_term_relationships AS tt2 ON (vsrc_posts.ID = tt2.object_id) WHERE 1=1 AND (
vsrc_term_relationships.term_taxonomy_id IN (351)
AND
tt1.term_taxonomy_id IN (259,263,274,314)
AND
tt2.term_taxonomy_id IN (348)
) AND vsrc_posts.post_type = 'product' AND ((vsrc_posts.post_status = 'publish')) GROUP BY vsrc_posts.ID ORDER BY vsrc_posts.post_date DESC
Array
(
[tax_query] => Array
(
[0] => Array
(
[taxonomy] => pa_timing
[field] => slug
[terms] => Array
(
[0] => day
)
)
[1] => Array
(
[taxonomy] => pa_size
[fields] => slug
[terms] => Array
(
[0] => s
)
)
)
[post_type] => product
[post_status] => publish
[posts_per_page] => -1
[product_cat] => pads
[error] =>
[m] =>
[p] => 0
[post_parent] =>
[subpost] =>
[subpost_id] =>
[attachment] =>
[attachment_id] => 0
[name] =>
[static] =>
[pagename] =>
[page_id] => 0
[second] =>
[minute] =>
[hour] =>
[day] => 0
[monthnum] => 0
[year] => 0
[w] => 0
[category_name] =>
[tag] =>
[cat] =>
[tag_id] =>
[author] =>
[author_name] =>
[feed] =>
[tb] =>
[paged] => 0
[meta_key] =>
[meta_value] =>
[preview] =>
[s] =>
[sentence] =>
[title] =>
[fields] =>
[menu_order] =>
[embed] =>
[category__in] => Array
(
)
[category__not_in] => Array
(
)
[category__and] => Array
(
)
[post__in] => Array
(
)
[post__not_in] => Array
(
)
[post_name__in] => Array
(
)
[tag__in] => Array
(
)
[tag__not_in] => Array
(
)
[tag__and] => Array
(
)
[tag_slug__in] => Array
(
)
[tag_slug__and] => Array
(
)
[post_parent__in] => Array
(
)
[post_parent__not_in] => Array
(
)
[author__in] => Array
(
)
[author__not_in] => Array
(
)
[ignore_sticky_posts] =>
[suppress_filters] =>
[cache_results] => 1
[update_post_term_cache] => 1
[lazy_load_term_meta] => 1
[update_post_meta_cache] => 1
[nopaging] => 1
[comments_per_page] => 50
[no_found_rows] =>
[taxonomy] => pa_timing
[term] => day
[order] => DESC
)
But when I just hardcode the array and pass it to WP_Query it produces
SELECT vsrc_posts.* FROM vsrc_posts LEFT JOIN vsrc_term_relationships ON (vsrc_posts.ID = vsrc_term_relationships.object_id) LEFT JOIN vsrc_term_relationships AS tt1 ON (vsrc_posts.ID = tt1.object_id) LEFT JOIN vsrc_term_relationships AS tt2 ON (vsrc_posts.ID = tt2.object_id) WHERE 1=1 AND (
vsrc_term_relationships.term_taxonomy_id IN (351)
AND
tt1.term_taxonomy_id IN (274)
AND
tt2.term_taxonomy_id IN (348)
) AND vsrc_posts.post_type = 'product' AND ((vsrc_posts.post_status = 'publish')) GROUP BY vsrc_posts.ID ORDER BY vsrc_posts.post_date DESC
Array
(
[tax_query] => Array
(
[0] => Array
(
[taxonomy] => pa_timing
[field] => slug
[terms] => Array
(
[0] => day
)
)
[1] => Array
(
[taxonomy] => pa_size
[field] => slug
[terms] => Array
(
[0] => s
)
)
)
[post_type] => product
[post_status] => publish
[posts_per_page] => -1
[product_cat] => pads
[error] =>
[m] =>
[p] => 0
[post_parent] =>
[subpost] =>
[subpost_id] =>
[attachment] =>
[attachment_id] => 0
[name] =>
[static] =>
[pagename] =>
[page_id] => 0
[second] =>
[minute] =>
[hour] =>
[day] => 0
[monthnum] => 0
[year] => 0
[w] => 0
[category_name] =>
[tag] =>
[cat] =>
[tag_id] =>
[author] =>
[author_name] =>
[feed] =>
[tb] =>
[paged] => 0
[meta_key] =>
[meta_value] =>
[preview] =>
[s] =>
[sentence] =>
[title] =>
[fields] =>
[menu_order] =>
[embed] =>
[category__in] => Array
(
)
[category__not_in] => Array
(
)
[category__and] => Array
(
)
[post__in] => Array
(
)
[post__not_in] => Array
(
)
[post_name__in] => Array
(
)
[tag__in] => Array
(
)
[tag__not_in] => Array
(
)
[tag__and] => Array
(
)
[tag_slug__in] => Array
(
)
[tag_slug__and] => Array
(
)
[post_parent__in] => Array
(
)
[post_parent__not_in] => Array
(
)
[author__in] => Array
(
)
[author__not_in] => Array
(
)
[ignore_sticky_posts] =>
[suppress_filters] =>
[cache_results] => 1
[update_post_term_cache] => 1
[lazy_load_term_meta] => 1
[update_post_meta_cache] => 1
[nopaging] => 1
[comments_per_page] => 50
[no_found_rows] =>
[taxonomy] => pa_timing
[term] => day
[order] => DESC
)
Which I expect WP_Query to produce. the problem is that WP_query is not producing for the dynamic query. Is there something I am missing
$dayArg = array(
'tax_query' => array(
array(
'taxonomy' => 'pa_timing',
'field' => 'slug',
'terms' => array( 'day' )
),
array(
'taxonomy' => 'pa_size',
'field' => 'slug',
'terms' => array( 's' )
)
),
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => - 1,
'product_cat' => 'pads'
)
This is argument I am passing to WP_Query one generating dynamically and one hardcoding it.
php wordpress woocommerce
add a comment |
I have a form from where clicks on the attribute and based on that click, I change my query to fetch relevant results
Below Array is generated dynamically based on user selection
Array
(
[tax_query] => Array
(
[0] => Array
(
[taxonomy] => pa_timing
[field] => slug
[terms] => Array
(
[0] => day
)
)
[1] => Array
(
[taxonomy] => pa_size
[fields] => slug
[terms] => Array
(
[0] => s
)
)
)
[post_type] => product
[post_status] => publish
[product_cat] => pads
[posts_per_page] => -1
)
Based on the above array WP_Query generated
SELECT vsrc_posts.* FROM vsrc_posts LEFT JOIN vsrc_term_relationships ON (vsrc_posts.ID = vsrc_term_relationships.object_id) LEFT JOIN vsrc_term_relationships AS tt1 ON (vsrc_posts.ID = tt1.object_id) LEFT JOIN vsrc_term_relationships AS tt2 ON (vsrc_posts.ID = tt2.object_id) WHERE 1=1 AND (
vsrc_term_relationships.term_taxonomy_id IN (351)
AND
tt1.term_taxonomy_id IN (259,263,274,314)
AND
tt2.term_taxonomy_id IN (348)
) AND vsrc_posts.post_type = 'product' AND ((vsrc_posts.post_status = 'publish')) GROUP BY vsrc_posts.ID ORDER BY vsrc_posts.post_date DESC
Array
(
[tax_query] => Array
(
[0] => Array
(
[taxonomy] => pa_timing
[field] => slug
[terms] => Array
(
[0] => day
)
)
[1] => Array
(
[taxonomy] => pa_size
[fields] => slug
[terms] => Array
(
[0] => s
)
)
)
[post_type] => product
[post_status] => publish
[posts_per_page] => -1
[product_cat] => pads
[error] =>
[m] =>
[p] => 0
[post_parent] =>
[subpost] =>
[subpost_id] =>
[attachment] =>
[attachment_id] => 0
[name] =>
[static] =>
[pagename] =>
[page_id] => 0
[second] =>
[minute] =>
[hour] =>
[day] => 0
[monthnum] => 0
[year] => 0
[w] => 0
[category_name] =>
[tag] =>
[cat] =>
[tag_id] =>
[author] =>
[author_name] =>
[feed] =>
[tb] =>
[paged] => 0
[meta_key] =>
[meta_value] =>
[preview] =>
[s] =>
[sentence] =>
[title] =>
[fields] =>
[menu_order] =>
[embed] =>
[category__in] => Array
(
)
[category__not_in] => Array
(
)
[category__and] => Array
(
)
[post__in] => Array
(
)
[post__not_in] => Array
(
)
[post_name__in] => Array
(
)
[tag__in] => Array
(
)
[tag__not_in] => Array
(
)
[tag__and] => Array
(
)
[tag_slug__in] => Array
(
)
[tag_slug__and] => Array
(
)
[post_parent__in] => Array
(
)
[post_parent__not_in] => Array
(
)
[author__in] => Array
(
)
[author__not_in] => Array
(
)
[ignore_sticky_posts] =>
[suppress_filters] =>
[cache_results] => 1
[update_post_term_cache] => 1
[lazy_load_term_meta] => 1
[update_post_meta_cache] => 1
[nopaging] => 1
[comments_per_page] => 50
[no_found_rows] =>
[taxonomy] => pa_timing
[term] => day
[order] => DESC
)
But when I just hardcode the array and pass it to WP_Query it produces
SELECT vsrc_posts.* FROM vsrc_posts LEFT JOIN vsrc_term_relationships ON (vsrc_posts.ID = vsrc_term_relationships.object_id) LEFT JOIN vsrc_term_relationships AS tt1 ON (vsrc_posts.ID = tt1.object_id) LEFT JOIN vsrc_term_relationships AS tt2 ON (vsrc_posts.ID = tt2.object_id) WHERE 1=1 AND (
vsrc_term_relationships.term_taxonomy_id IN (351)
AND
tt1.term_taxonomy_id IN (274)
AND
tt2.term_taxonomy_id IN (348)
) AND vsrc_posts.post_type = 'product' AND ((vsrc_posts.post_status = 'publish')) GROUP BY vsrc_posts.ID ORDER BY vsrc_posts.post_date DESC
Array
(
[tax_query] => Array
(
[0] => Array
(
[taxonomy] => pa_timing
[field] => slug
[terms] => Array
(
[0] => day
)
)
[1] => Array
(
[taxonomy] => pa_size
[field] => slug
[terms] => Array
(
[0] => s
)
)
)
[post_type] => product
[post_status] => publish
[posts_per_page] => -1
[product_cat] => pads
[error] =>
[m] =>
[p] => 0
[post_parent] =>
[subpost] =>
[subpost_id] =>
[attachment] =>
[attachment_id] => 0
[name] =>
[static] =>
[pagename] =>
[page_id] => 0
[second] =>
[minute] =>
[hour] =>
[day] => 0
[monthnum] => 0
[year] => 0
[w] => 0
[category_name] =>
[tag] =>
[cat] =>
[tag_id] =>
[author] =>
[author_name] =>
[feed] =>
[tb] =>
[paged] => 0
[meta_key] =>
[meta_value] =>
[preview] =>
[s] =>
[sentence] =>
[title] =>
[fields] =>
[menu_order] =>
[embed] =>
[category__in] => Array
(
)
[category__not_in] => Array
(
)
[category__and] => Array
(
)
[post__in] => Array
(
)
[post__not_in] => Array
(
)
[post_name__in] => Array
(
)
[tag__in] => Array
(
)
[tag__not_in] => Array
(
)
[tag__and] => Array
(
)
[tag_slug__in] => Array
(
)
[tag_slug__and] => Array
(
)
[post_parent__in] => Array
(
)
[post_parent__not_in] => Array
(
)
[author__in] => Array
(
)
[author__not_in] => Array
(
)
[ignore_sticky_posts] =>
[suppress_filters] =>
[cache_results] => 1
[update_post_term_cache] => 1
[lazy_load_term_meta] => 1
[update_post_meta_cache] => 1
[nopaging] => 1
[comments_per_page] => 50
[no_found_rows] =>
[taxonomy] => pa_timing
[term] => day
[order] => DESC
)
Which I expect WP_Query to produce. the problem is that WP_query is not producing for the dynamic query. Is there something I am missing
$dayArg = array(
'tax_query' => array(
array(
'taxonomy' => 'pa_timing',
'field' => 'slug',
'terms' => array( 'day' )
),
array(
'taxonomy' => 'pa_size',
'field' => 'slug',
'terms' => array( 's' )
)
),
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => - 1,
'product_cat' => 'pads'
)
This is argument I am passing to WP_Query one generating dynamically and one hardcoding it.
php wordpress woocommerce
@LoicTheAztec I have updated my question with related WP_Query arguments
– Mustanish Altamash
Mar 27 at 10:22
I have updated my answer I am using.push() function to generate tax_query hope I made my question clear
– Mustanish Altamash
Mar 27 at 17:24
add a comment |
I have a form from where clicks on the attribute and based on that click, I change my query to fetch relevant results
Below Array is generated dynamically based on user selection
Array
(
[tax_query] => Array
(
[0] => Array
(
[taxonomy] => pa_timing
[field] => slug
[terms] => Array
(
[0] => day
)
)
[1] => Array
(
[taxonomy] => pa_size
[fields] => slug
[terms] => Array
(
[0] => s
)
)
)
[post_type] => product
[post_status] => publish
[product_cat] => pads
[posts_per_page] => -1
)
Based on the above array WP_Query generated
SELECT vsrc_posts.* FROM vsrc_posts LEFT JOIN vsrc_term_relationships ON (vsrc_posts.ID = vsrc_term_relationships.object_id) LEFT JOIN vsrc_term_relationships AS tt1 ON (vsrc_posts.ID = tt1.object_id) LEFT JOIN vsrc_term_relationships AS tt2 ON (vsrc_posts.ID = tt2.object_id) WHERE 1=1 AND (
vsrc_term_relationships.term_taxonomy_id IN (351)
AND
tt1.term_taxonomy_id IN (259,263,274,314)
AND
tt2.term_taxonomy_id IN (348)
) AND vsrc_posts.post_type = 'product' AND ((vsrc_posts.post_status = 'publish')) GROUP BY vsrc_posts.ID ORDER BY vsrc_posts.post_date DESC
Array
(
[tax_query] => Array
(
[0] => Array
(
[taxonomy] => pa_timing
[field] => slug
[terms] => Array
(
[0] => day
)
)
[1] => Array
(
[taxonomy] => pa_size
[fields] => slug
[terms] => Array
(
[0] => s
)
)
)
[post_type] => product
[post_status] => publish
[posts_per_page] => -1
[product_cat] => pads
[error] =>
[m] =>
[p] => 0
[post_parent] =>
[subpost] =>
[subpost_id] =>
[attachment] =>
[attachment_id] => 0
[name] =>
[static] =>
[pagename] =>
[page_id] => 0
[second] =>
[minute] =>
[hour] =>
[day] => 0
[monthnum] => 0
[year] => 0
[w] => 0
[category_name] =>
[tag] =>
[cat] =>
[tag_id] =>
[author] =>
[author_name] =>
[feed] =>
[tb] =>
[paged] => 0
[meta_key] =>
[meta_value] =>
[preview] =>
[s] =>
[sentence] =>
[title] =>
[fields] =>
[menu_order] =>
[embed] =>
[category__in] => Array
(
)
[category__not_in] => Array
(
)
[category__and] => Array
(
)
[post__in] => Array
(
)
[post__not_in] => Array
(
)
[post_name__in] => Array
(
)
[tag__in] => Array
(
)
[tag__not_in] => Array
(
)
[tag__and] => Array
(
)
[tag_slug__in] => Array
(
)
[tag_slug__and] => Array
(
)
[post_parent__in] => Array
(
)
[post_parent__not_in] => Array
(
)
[author__in] => Array
(
)
[author__not_in] => Array
(
)
[ignore_sticky_posts] =>
[suppress_filters] =>
[cache_results] => 1
[update_post_term_cache] => 1
[lazy_load_term_meta] => 1
[update_post_meta_cache] => 1
[nopaging] => 1
[comments_per_page] => 50
[no_found_rows] =>
[taxonomy] => pa_timing
[term] => day
[order] => DESC
)
But when I just hardcode the array and pass it to WP_Query it produces
SELECT vsrc_posts.* FROM vsrc_posts LEFT JOIN vsrc_term_relationships ON (vsrc_posts.ID = vsrc_term_relationships.object_id) LEFT JOIN vsrc_term_relationships AS tt1 ON (vsrc_posts.ID = tt1.object_id) LEFT JOIN vsrc_term_relationships AS tt2 ON (vsrc_posts.ID = tt2.object_id) WHERE 1=1 AND (
vsrc_term_relationships.term_taxonomy_id IN (351)
AND
tt1.term_taxonomy_id IN (274)
AND
tt2.term_taxonomy_id IN (348)
) AND vsrc_posts.post_type = 'product' AND ((vsrc_posts.post_status = 'publish')) GROUP BY vsrc_posts.ID ORDER BY vsrc_posts.post_date DESC
Array
(
[tax_query] => Array
(
[0] => Array
(
[taxonomy] => pa_timing
[field] => slug
[terms] => Array
(
[0] => day
)
)
[1] => Array
(
[taxonomy] => pa_size
[field] => slug
[terms] => Array
(
[0] => s
)
)
)
[post_type] => product
[post_status] => publish
[posts_per_page] => -1
[product_cat] => pads
[error] =>
[m] =>
[p] => 0
[post_parent] =>
[subpost] =>
[subpost_id] =>
[attachment] =>
[attachment_id] => 0
[name] =>
[static] =>
[pagename] =>
[page_id] => 0
[second] =>
[minute] =>
[hour] =>
[day] => 0
[monthnum] => 0
[year] => 0
[w] => 0
[category_name] =>
[tag] =>
[cat] =>
[tag_id] =>
[author] =>
[author_name] =>
[feed] =>
[tb] =>
[paged] => 0
[meta_key] =>
[meta_value] =>
[preview] =>
[s] =>
[sentence] =>
[title] =>
[fields] =>
[menu_order] =>
[embed] =>
[category__in] => Array
(
)
[category__not_in] => Array
(
)
[category__and] => Array
(
)
[post__in] => Array
(
)
[post__not_in] => Array
(
)
[post_name__in] => Array
(
)
[tag__in] => Array
(
)
[tag__not_in] => Array
(
)
[tag__and] => Array
(
)
[tag_slug__in] => Array
(
)
[tag_slug__and] => Array
(
)
[post_parent__in] => Array
(
)
[post_parent__not_in] => Array
(
)
[author__in] => Array
(
)
[author__not_in] => Array
(
)
[ignore_sticky_posts] =>
[suppress_filters] =>
[cache_results] => 1
[update_post_term_cache] => 1
[lazy_load_term_meta] => 1
[update_post_meta_cache] => 1
[nopaging] => 1
[comments_per_page] => 50
[no_found_rows] =>
[taxonomy] => pa_timing
[term] => day
[order] => DESC
)
Which I expect WP_Query to produce. the problem is that WP_query is not producing for the dynamic query. Is there something I am missing
$dayArg = array(
'tax_query' => array(
array(
'taxonomy' => 'pa_timing',
'field' => 'slug',
'terms' => array( 'day' )
),
array(
'taxonomy' => 'pa_size',
'field' => 'slug',
'terms' => array( 's' )
)
),
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => - 1,
'product_cat' => 'pads'
)
This is argument I am passing to WP_Query one generating dynamically and one hardcoding it.
php wordpress woocommerce
I have a form from where clicks on the attribute and based on that click, I change my query to fetch relevant results
Below Array is generated dynamically based on user selection
Array
(
[tax_query] => Array
(
[0] => Array
(
[taxonomy] => pa_timing
[field] => slug
[terms] => Array
(
[0] => day
)
)
[1] => Array
(
[taxonomy] => pa_size
[fields] => slug
[terms] => Array
(
[0] => s
)
)
)
[post_type] => product
[post_status] => publish
[product_cat] => pads
[posts_per_page] => -1
)
Based on the above array WP_Query generated
SELECT vsrc_posts.* FROM vsrc_posts LEFT JOIN vsrc_term_relationships ON (vsrc_posts.ID = vsrc_term_relationships.object_id) LEFT JOIN vsrc_term_relationships AS tt1 ON (vsrc_posts.ID = tt1.object_id) LEFT JOIN vsrc_term_relationships AS tt2 ON (vsrc_posts.ID = tt2.object_id) WHERE 1=1 AND (
vsrc_term_relationships.term_taxonomy_id IN (351)
AND
tt1.term_taxonomy_id IN (259,263,274,314)
AND
tt2.term_taxonomy_id IN (348)
) AND vsrc_posts.post_type = 'product' AND ((vsrc_posts.post_status = 'publish')) GROUP BY vsrc_posts.ID ORDER BY vsrc_posts.post_date DESC
Array
(
[tax_query] => Array
(
[0] => Array
(
[taxonomy] => pa_timing
[field] => slug
[terms] => Array
(
[0] => day
)
)
[1] => Array
(
[taxonomy] => pa_size
[fields] => slug
[terms] => Array
(
[0] => s
)
)
)
[post_type] => product
[post_status] => publish
[posts_per_page] => -1
[product_cat] => pads
[error] =>
[m] =>
[p] => 0
[post_parent] =>
[subpost] =>
[subpost_id] =>
[attachment] =>
[attachment_id] => 0
[name] =>
[static] =>
[pagename] =>
[page_id] => 0
[second] =>
[minute] =>
[hour] =>
[day] => 0
[monthnum] => 0
[year] => 0
[w] => 0
[category_name] =>
[tag] =>
[cat] =>
[tag_id] =>
[author] =>
[author_name] =>
[feed] =>
[tb] =>
[paged] => 0
[meta_key] =>
[meta_value] =>
[preview] =>
[s] =>
[sentence] =>
[title] =>
[fields] =>
[menu_order] =>
[embed] =>
[category__in] => Array
(
)
[category__not_in] => Array
(
)
[category__and] => Array
(
)
[post__in] => Array
(
)
[post__not_in] => Array
(
)
[post_name__in] => Array
(
)
[tag__in] => Array
(
)
[tag__not_in] => Array
(
)
[tag__and] => Array
(
)
[tag_slug__in] => Array
(
)
[tag_slug__and] => Array
(
)
[post_parent__in] => Array
(
)
[post_parent__not_in] => Array
(
)
[author__in] => Array
(
)
[author__not_in] => Array
(
)
[ignore_sticky_posts] =>
[suppress_filters] =>
[cache_results] => 1
[update_post_term_cache] => 1
[lazy_load_term_meta] => 1
[update_post_meta_cache] => 1
[nopaging] => 1
[comments_per_page] => 50
[no_found_rows] =>
[taxonomy] => pa_timing
[term] => day
[order] => DESC
)
But when I just hardcode the array and pass it to WP_Query it produces
SELECT vsrc_posts.* FROM vsrc_posts LEFT JOIN vsrc_term_relationships ON (vsrc_posts.ID = vsrc_term_relationships.object_id) LEFT JOIN vsrc_term_relationships AS tt1 ON (vsrc_posts.ID = tt1.object_id) LEFT JOIN vsrc_term_relationships AS tt2 ON (vsrc_posts.ID = tt2.object_id) WHERE 1=1 AND (
vsrc_term_relationships.term_taxonomy_id IN (351)
AND
tt1.term_taxonomy_id IN (274)
AND
tt2.term_taxonomy_id IN (348)
) AND vsrc_posts.post_type = 'product' AND ((vsrc_posts.post_status = 'publish')) GROUP BY vsrc_posts.ID ORDER BY vsrc_posts.post_date DESC
Array
(
[tax_query] => Array
(
[0] => Array
(
[taxonomy] => pa_timing
[field] => slug
[terms] => Array
(
[0] => day
)
)
[1] => Array
(
[taxonomy] => pa_size
[field] => slug
[terms] => Array
(
[0] => s
)
)
)
[post_type] => product
[post_status] => publish
[posts_per_page] => -1
[product_cat] => pads
[error] =>
[m] =>
[p] => 0
[post_parent] =>
[subpost] =>
[subpost_id] =>
[attachment] =>
[attachment_id] => 0
[name] =>
[static] =>
[pagename] =>
[page_id] => 0
[second] =>
[minute] =>
[hour] =>
[day] => 0
[monthnum] => 0
[year] => 0
[w] => 0
[category_name] =>
[tag] =>
[cat] =>
[tag_id] =>
[author] =>
[author_name] =>
[feed] =>
[tb] =>
[paged] => 0
[meta_key] =>
[meta_value] =>
[preview] =>
[s] =>
[sentence] =>
[title] =>
[fields] =>
[menu_order] =>
[embed] =>
[category__in] => Array
(
)
[category__not_in] => Array
(
)
[category__and] => Array
(
)
[post__in] => Array
(
)
[post__not_in] => Array
(
)
[post_name__in] => Array
(
)
[tag__in] => Array
(
)
[tag__not_in] => Array
(
)
[tag__and] => Array
(
)
[tag_slug__in] => Array
(
)
[tag_slug__and] => Array
(
)
[post_parent__in] => Array
(
)
[post_parent__not_in] => Array
(
)
[author__in] => Array
(
)
[author__not_in] => Array
(
)
[ignore_sticky_posts] =>
[suppress_filters] =>
[cache_results] => 1
[update_post_term_cache] => 1
[lazy_load_term_meta] => 1
[update_post_meta_cache] => 1
[nopaging] => 1
[comments_per_page] => 50
[no_found_rows] =>
[taxonomy] => pa_timing
[term] => day
[order] => DESC
)
Which I expect WP_Query to produce. the problem is that WP_query is not producing for the dynamic query. Is there something I am missing
$dayArg = array(
'tax_query' => array(
array(
'taxonomy' => 'pa_timing',
'field' => 'slug',
'terms' => array( 'day' )
),
array(
'taxonomy' => 'pa_size',
'field' => 'slug',
'terms' => array( 's' )
)
),
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => - 1,
'product_cat' => 'pads'
)
This is argument I am passing to WP_Query one generating dynamically and one hardcoding it.
php wordpress woocommerce
php wordpress woocommerce
edited Mar 27 at 17:22
Mustanish Altamash
asked Mar 26 at 21:34
Mustanish AltamashMustanish Altamash
661 silver badge6 bronze badges
661 silver badge6 bronze badges
@LoicTheAztec I have updated my question with related WP_Query arguments
– Mustanish Altamash
Mar 27 at 10:22
I have updated my answer I am using.push() function to generate tax_query hope I made my question clear
– Mustanish Altamash
Mar 27 at 17:24
add a comment |
@LoicTheAztec I have updated my question with related WP_Query arguments
– Mustanish Altamash
Mar 27 at 10:22
I have updated my answer I am using.push() function to generate tax_query hope I made my question clear
– Mustanish Altamash
Mar 27 at 17:24
@LoicTheAztec I have updated my question with related WP_Query arguments
– Mustanish Altamash
Mar 27 at 10:22
@LoicTheAztec I have updated my question with related WP_Query arguments
– Mustanish Altamash
Mar 27 at 10:22
I have updated my answer I am using.push() function to generate tax_query hope I made my question clear
– Mustanish Altamash
Mar 27 at 17:24
I have updated my answer I am using.push() function to generate tax_query hope I made my question clear
– Mustanish Altamash
Mar 27 at 17:24
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55366546%2fusing-dynamic-multiple-attributes-with-wp-query%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55366546%2fusing-dynamic-multiple-attributes-with-wp-query%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
@LoicTheAztec I have updated my question with related WP_Query arguments
– Mustanish Altamash
Mar 27 at 10:22
I have updated my answer I am using.push() function to generate tax_query hope I made my question clear
– Mustanish Altamash
Mar 27 at 17:24