What happen when a post (product) didnt have a guid,because it has the same image with another product ?

For example:


select guid from wp_posts where post_type='attachment' and post_parent=num 

Returns nothing.


select guid from wp_posts where ID=num

Returns the url of product.

In this case how should i find the image url of that product?


Firstly, the GUID is not the URL. It is a "globally unique identifier". WordPress uses the URL for this purpose, but accessing it is not a reliable way to get the URL for anything (this was a bad idea, but is kept this way for backwards compatibility).

It's not possible to query the image URL from the database directly. The full URL is not stored there. But if you have the ID for a product and want to get the URL for its image you can do this:

$product   = wc_get_product( $product_id );
$image_id  = $product->get_image_id();
$image_url = wp_get_attachment_image_url( $image_id, 'full' );
  • Thank you,but If i want to find it from database,i mean in which table i can find it? – user8761967 May 23 at 7:29
  • As I said, the full URL is not stored in the database. It's programmatically generated based on a few factors, such as the site URL, permalink structure, post type rewrite arguments, upload directory structure, and wp-config settings. You need to get it using a function like the one in my answer. – Jacob Peattie May 23 at 7:36

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.