Hi folks,
this is the thing I want to accomplish: On a single post page for a product I want to show the corresponding sales person. For the sales persons I have also a custom post type. Both related, all with ACPT.
This is the issue I am are facing:
The ACPT field is returning the post ID, however, I am unable to integrate it into the Bricks Loop meta query. I want the loop to display the post that has the ID.
Has anyone a hint for me?
Thank you in advance!
Heiko
I do not own ACPT and do not know the exact way to fetch field values programmatically. But it should be understandable nevertheless.
You do not need a meta query in this case. You can use the bricks/posts/query_vars hook and fetch the sales person post directly like this:
add_filter( 'bricks/posts/query_vars', function( $query_vars, $settings, $element_id ) {
if ( $element_id == 'YOUR_QUERY_LOOP_ELEMENT_ID' && function_exists( 'get_acpt_field' ) ) {
$query_vars['post_type'] = 'YOUR_SALES_PERSON_POST_TYPE'; // adding this line you do not need any specific query settings in the UI
$sales_person_id = get_acpt_field( ... ); // correctly get the custom field value here
$query_vars['p'] = $sales_person_id;
}
return $query_vars;
}, 10, 3 );
2 Likes
Hi aslotta, thanks so much for helping me out here! Very much appreciated. I’ll try out your suggestion!
Hi Heiko,
did you ever find a working solution for your question (displaying ACPT related posts in Bricks, ideally via Bricks query loop) ?
And if so, would you mind sharing it?
Thanks in advance
Marc
Hi Marc,
I didn’t t this moment and also the dev of ACPT was on holiday back then (and I was under pressure with a project). So I switched to Jet Engine. Which worked fine for this.
So: For now I would suggest you to contact the dev of ACPT who normally answers really quickly and probably will help you with this. I assume: this feature now works better than it did half a year ago.
Kind regards,
Heiko
Hi Heiko,
many thanks for the reply.
I will do as you suggest and post the response here, for documentation purpose.
Cheers,
Marc
I hook into this topic, I have exactly this challenge now with ACPT and will update this topic with a solution I find.
This is the way:
So the Loop must be:
// Retrieve the related post IDs from the 'specialties' relational field
$postIds = '{cf_metabox-name_field-name}';
// Convert the comma-separated string into an array
$postIds = explode(",", $postIds);
// Return the query parameters
return [
'post_type' => 'put here your custom post type name', // Specify the related post type
'posts_per_page' => -1, // Retrieve all related posts
'post__in' => $postIds, // Filter posts by the related IDs
];