Ecommerce Shopify WordPress Discussion

Get list of products from wordpress table using Laravel

I'm working on a Laravel project where I need to retrieve products from a WordPress database based on a specific attribute value. The attribute in question is "brand," and I'm trying to fetch products where the brand is "7M." I'm using Laravel Eloquent and have set up models for Product and PostMeta to interact with the WordPress tables. class Product extends Model{ public function meta() { return $this->hasMany('App\PostMeta', 'post_id'); }} class PostMeta extends Model{ public function scopeMetaKey($query, $key) { return $query->where('meta_key', $key); } public function scopeMetaValue($query, $value) { return $query->where('meta_value', $value); } } $brandName = '7M'; $metaKey = 'pa_brand'; // Replace with the actual meta key for the brand attribute $product = Product::whereHas('meta', function ($query) use ($brandName, $metaKey) { $query->metaKey($metaKey)->metaValue($brandName); })->first(); this is the solution suggested by chatgpt, coz I am not an expert of WordPress tables. when I execute this query it returns me null, but I have a product whose attribute has brand =7M.
Perhaps you can debug this by examining the actual SQL query sent to the database. \DB::enableQueryLog(); // Enable the query log // Your Eloquent queries dd(\DB::getQueryLog()); // Display the query logs Hope this helps.

December 30, 2023

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.