במזהה שאילתא לכתוב prquery
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_6162b054f3791',
'title' => 'סידור מוצרים שאילתה',
'fields' => array(
array(
'key' => 'field_6162b0731c541',
'label' => 'שאילתא',
'name' => 'product_query',
'type' => 'relationship',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'post_type' => array(
0 => 'product',
),
'taxonomy' => '',
'filters' => array(
0 => 'search',
1 => 'post_type',
2 => 'taxonomy',
),
'elements' => array(
0 => 'featured_image',
),
'min' => '',
'max' => '',
'return_format' => 'id',
),
array(
'key' => 'field_6163f912266e0',
'label' => 'הגבלת כמות מוצרים',
'name' => 'product_query_limit',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
'location' => array(
array(
array(
'param' => 'page',
'operator' => '==',
'value' => '16',
),
),
array(
array(
'param' => 'taxonomy',
'operator' => '==',
'value' => 'product_cat',
),
),
),
'menu_order' => 0,
'position' => 'acf_after_title',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
endif;
add_action( 'elementor/query/prquery','gs_products_custom_order');
function gs_products_custom_order( $query ){
//if ( get_field( 'field_name' ) ):
$products='';
$product_query_limit='';
if(is_archive()):
$term = get_queried_object();
$products = get_term_meta($term->term_id,'product_query', true);
if(empty($products)):
$query->set('taxonomy','product_cat');
$query->set('term',$term->slug);
endif;
$product_query_limit = get_term_meta(get_the_ID(),'product_query_limit', true);
else:
$products = get_post_meta(get_the_ID(),'product_query', true);
$product_query_limit = get_post_meta(get_the_ID(),'product_query_limit', true);
endif;
$query->set('posts_per_page', $product_query_limit );
$query->set('post_type', [ 'product' ] );
$query->set('orderby','post__in');
$query->set('order','DESC');
$query->set('post__in',$products);
};
Code language: PHP (php)