John Davidson

php - woocommerce, product link by reviews loop

0 comments
Message:


I created the very simple loop here, the aim is to extract only reviews that have a value equal to or greater than 4 stars. And so far so good. Now from this loop I would also like to get the link to the specific product. Anyone have any idea how to get this information?


$reviews = get_comments( array(
'status' => 'approve',
'post_status' => 'publish',
'post_type' => 'product',
'meta_query' => array( array(
'key' => 'rating',
'value' => array('4','5'),
) ),
) );

foreach( $reviews as $review) {

/* stuff */

}


My Answer:
'approve',
'post_status' => 'publish',
'post_type' => 'product',
'meta_query' => array(
array(
'key' => 'rating',
'value' => 4,
'compare' => '>=',
'type' => 'NUMERIC',
),
),
);

foreach ( $reviews as $review ) {
$product_id = $review->comment_post_ID;
$product_link = get_permalink( $product_id );
echo 'Product Link';
}

Rate this post

3 of 5 based on 2926 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us