I have custom post type of Reviews
In Reviews I have a field called agent_name
I want to create a query loop that grabs all review that are the following:
{post_title} = agent_name
I have no idea how to do this in the query loop builder.
I have custom post type of Reviews
In Reviews I have a field called agent_name
I want to create a query loop that grabs all review that are the following:
{post_title} = agent_name
I have no idea how to do this in the query loop builder.
What field? If it’s a wordpress field use
cf_fieldName
If it’s ACF / METABOX - you can get the field from the dynamic options.
You don’t wan’t post title=
You want {acf_fieldName} =
Use a query for POST_TYPE = REVIEW
Use the meta query for matching the field name.
I am using Postype and one of the fields is called agentname.
I am trying to compare the title of the page with the agentname post type field
Maybe I am approaching it wrong but this seems to be the best way to do it.
The end result is page title = Post Type field agent name
I am using ACF Should I be using metabox
How do I use the meta query ?
I could also compare the post type field to taxonomy
Meta Key
Meta Value
Compare
ACF is fine. I’m still not sure I understand.
I think you either want to open all posts where AGENT = X
Based on the agent field. In which case use the meta query. Open your query, scroll down to this bit:
OR
Open the posts and add the AGENT name to the title.
In which case simply set up a query to get all posts. Inside the query, add a headline and make it {post title} {acf_agents_name}
It may be important to note that you can use POSTS ELEMENT to get posts, but for what you want, you should simply add a query to a container, and then put the things you want (eg title and agent) into the container using blocks and dynamic data.
OR
You want to open all posts where the post title contains the agents name. This you can’t do with just Bricks - you would have to write your own function. BUT… it’s a weird thing to do anyway. Just put the agents name in a custom field and not in the title - then filter with that as above.
This is all I am trying to do.
I set up a custom Post Type called Testimonials
I have 50 sales reps.
Clients of each sales rep will go to a sales rep bio page and fill out a testimonial via a form.
I want to return all of the Testimonials on the sales reps page.
I have create a template in Bricks for the agents. I want to configure it in such a way that the testimonials show for each sales rep .
I was thinking I could match the title of the page ie Joe blow with the agent name in the custom post type.
Page title = Custom post type field of agent_name
Pretty simple
or
Ok. Nothing like your first question…but simple enough.
However you record testimonials - make sure AGENT ID is a field in the testimonial (add it with ACF), and that it is populated with the ID of the agents profile (post_id of the agents profile) when the testimonials is created. ID is more reliable than name as it cannot be duplicated.
The template will show when on the agents profile page - so the POST_ID of the page will already be the ID you need.
Create QUERY = get posts, type testimonials, where META KEY {acf_agent_id} = META VALUE {post_id}
Will give you a list of testimonials.
Shouldn’t the meta key be a static value like agent_id? Otherwise its pulling the numeric value, which doesn’t exist.
so I got the following code:
I have custom code set after submit in Bricks and I am not able to get the form to populate the Post type testimonial.
function my_form_save_to_cpt( $form ) {
$fields = $form->get_fields();
// The Bricks Form ID is the last part of the CSS ID
// So if a form has a CSS ID of bricks-element-fszxsr, then the form ID is fszxsr
$formId = $fields['formId'];
// Replace this comment with the description of the form
// Copy and paste the IF block below to add custom action for other forms
if( $formId == 'mrrzrf' ){
$name = $fields['form-field-42ee3e'];
$email = $fields['form-field-5e8eb1'];
$messages = $fields['form-field-96bee2'];
$starrating = $fields['form-field-jpuifs'];
$photo = $fields['form-field-widvjg'];
$agentID = $fields['form-field-dgbvnt'];
$new_post = array();
$new_post['post_type'] = 'testimonial';
$new_post['post_status'] = 'publish';
if(isset($name) && !empty($name)){
$new_post['post_title'] = 'Testimonial from '.$name.'';
} else {
$new_post['post_title'] = 'Message from user';
}
if(isset($messages)){
$new_post['post_content'] = $messages;
} else {
$new_post['post_content'] = 'No comment was submitted';
}
if(isset($email) && !empty($email)){
$new_post['meta_input']['testimonial_email'] = $email;
}
if(isset($name) && !empty($name)){
$new_post['meta_input']['testimonial_name'] = $name;
}
if(isset($photo) && !empty($photo)){
$new_post['meta_input']['testimonial_photo'] = $photo;
}
if(isset($starrating) && !empty($starrating)){
$new_post['meta_input']['testimonial__star_rating'] = $starrating;
}
if(isset($agentID) && !empty($agentID)){
$new_post['meta_input']['testimonial_owner'] = $agentID;
}
if($post_id = wp_insert_post($new_post)){
} else {
}
return;
}
add_action( 'bricks/form/custom_action', 'my_form_save_to_cpt', 10, 1 );
};