I am trying to show custom fields of some products using elementor custom query. The products are coming just fine. But they have usage custom fields matching custom conditions. Have a look at this image to understand the situationProblem Statement Image 1

As you see, the usage will show as per the conditions, if all conditions are false, default usage will be shown. Now the usage is something like this, weekly 3 times morning only or daily both times, have a look at the next image and you will understand. Usage examples for Problem Statement

Now I have a table like this:

         Monday | Tuesday | Wednesday | Thursday | Friday | Saturday


So in first cell I want to show all the products that have Day 1 use as Morning and fill the entire table similarly.

I am querying the products for monday morning with this code :

function monday_morning_only($query_args){

$id_array = return_current_product_ids();
$query_args['post__in'] = $id_array;

$row_index = 0;
$meta_key_for_usage = 'personal_usage_condition_based_'.$row_index.'_custom_daily_usage_';
$query_args['meta_key'] = $meta_key_for_usage.'day_1';
$query_args['meta_value'] = array('Morning only','Morning and Evening');
$query_args['meta_compare'] = 'IN';

return $query_args;

This works, but shows products matching 1st condition only as I hardcoded the $row_index variable to 0. I also wrote a function to return the matching row_index, but how can I put row_index for each product inside this query? Or should I query separately and merge results? Or is there any better way? Please share your knowledge and guide me to solve this problem. Thanks.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.