skip to Main Content

Sorry if this is a duplicate, but I didn’t find it anywhere.
I need to get all the products belonging to a certain vendor via a raw SQL query.
I know both the vendor slug or id, but I couldn’t figure out exactly the relationship between the products and a vendor.

Can anyone share a complete SQL to do that or at least what is that relationship between tables.
Thanks for any advice!

2

Answers


  1. Chosen as BEST ANSWER

    I tried it and it works, thanks! :) One problem is that obviously you don't have access to the WP functions from an external script/language, but I found a solution that I share here too.

    You can include the WP function with this line

    require_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');

    So I created a PHP file where I used the above code and I generated a json structure with all the information I needed. Then I can access that from any external script/language. It's not raw SQL, but it does that job.

    Hope this solution helps someone that needs this.


  2. Here’s the code that I used on one of my sites:

    Note: Replace the $vendor_id with the ID of the vendor you have.

    $vendor_products_list  = $WCFM->wcfm_vendor_support->wcfm_get_products_by_vendor($vendor_id, 'publish', array('posts_per_page' => -1) );
    if ($vendor_products_list){
        foreach($vendor_products_list as $the_product){
            echo $the_product->ID;
        }
    }
    

    Note: It is not recommended to do RAW SQL in WordPress. Try to stick to the standard methods available to get desired output.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search