Hello,
I have a product in woocommerce, it has a custom field using a page link. This works fine.
When I am on that page, i would like to link back to the woocommerce product and also get all the woocommerce custom fields to use on this page.
this is my first attempt at the code with no luck. I have tried linking with both the current page ID and the permalink, neither work
$current_url = get_permalink();
echo $post->ID;
$args = array(
'numberposts' => 1000,
'post_type' => 'product',
'meta_key' => 'page_link',
'meta_value' => $post->ID
);
$loop = new WP_Query( $args );
echo $loop->request;
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
endwhile;
What does the page link field actually return? Does it return a plain URL? And is the value the field returns identical to what get_permalink() or $post->ID return?
The page link field returns the URL. Yes, this is just like using get_permalink(). When selecting pages/posts. ACF stores an array of post IDs. In order to reverse query this you need to do a “LIKE” query.
$args = array(
'numberposts' => 1000,
'post_type' => 'product',
'meta_key' => 'page_link',
'meta_value' => '"'.$post->ID.'"'.
'meta_compare' => 'LIKE'
);