1

Here are the args for my query :

$args = array(
        'post_type' => 'product',
        'posts_per_page' => -1,
        'meta_query' => array(
            array(
                'key' => 'vendor',
                'value' => 'farsi',
                'compare' => '=',
            ),
    )
    );

This doesn't work when topics is a string, it gets me all products, But I need to get all products that have meta data (vendor) farsi.

UPDATE:

i use this code that move out of stock products to last product in archive:

add_action( 'pre_get_posts', 'move_out_of_stock_products_to_end' );

When stop it, the query work good.

So what can do !!

  • 1
    Are you sure vendor is the meta_key and not wpcf-vendor? Please check in database and confirm. – Jiten Gaikwad Jun 14 '17 at 15:19
  • yes i check it in database – Johen Jun 15 '17 at 7:03
0

If you want to target meta key vendor and meta value farsi, you need to pass the following meta_query arguments:

$args = array(
    'posts_per_page' => -1,
    'post_type' => 'product',
    'meta_query' => array(
        array(
            'key'     => 'vendor',
            'value'   => 'farsi',
        )
    )
);

Also to note, as Jiten highlighted, your meta key may be wpcf-vendor.

  • i try and get me HTTP ERROR 500 – Johen Jun 15 '17 at 7:29
  • That error is not related to this particular code. Learn more about 500 here. – Christine Cooper Jun 15 '17 at 8:48
  • thank you.. now its same my code,, its get me all product have vendor farsi and null and empty ... !! – Johen Jun 15 '17 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.