I have a custom post type case_study
There are two sort of custom fields called sales_increase
and case_study
.
Each of these have custom fields that appear when selected while writing a new Case Study post via the Conditional Logic option in ACF, depending on which radio option is selected, radio_sales_incease
or radio_case_study
What I want to do is create two different WP_Querys, one just for posts that have the sales_increase
selected and another in the same template for full_case_study
. I’ve poured over every post related to radio buttons but I just can’t figure this out.
Here is the query I tried to write:
$args = array(
'numberposts' => -1,
'post_type' => 'case_study',
'meta_key' => 'case_radio',
'choices' => array(
'radio_sales_increase' => 'Sales Increase',
),
);
The only part of this that seems to work is the post_type
argument.
Here is the custom-fields code for radio selects that ACF exports if that helps:
array (
'key' => 'field_5592fcb8e266f',
'label' => 'Case Radio',
'name' => 'case_radio',
'type' => 'radio',
'instructions' => 'Select Case Study post type.',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array (
'radio_case_study' => 'Case Study',
'radio_sales_increase' => 'Sales Increase',
),
'other_choice' => 0,
'save_other_choice' => 0,
'default_value' => '',
'layout' => 'horizontal',
),
array (
'key' => 'field_5592fd1e644a4',
'label' => 'Case Study',
'name' => 'full_case_study',
'type' => 'wysiwyg',
'instructions' => 'Enter Case Study write up.',
'required' => 0,
'conditional_logic' => array (
array (
array (
'field' => 'field_5592fcb8e266f',
'operator' => '==',
'value' => 'radio_case_study',
),
),
),
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'tabs' => 'all',
'toolbar' => 'full',
'media_upload' => 1,
),
array (
'key' => 'field_5592fd74f5563',
'label' => 'Sales Increase',
'name' => 'sales_increase',
'type' => 'number',
'instructions' => 'Enter the sales increase percentage number.',
'required' => 0,
'conditional_logic' => array (
array (
array (
'field' => 'field_5592fcb8e266f',
'operator' => '==',
'value' => 'radio_sales_increase',
),
),
),
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'min' => '',
'max' => '',
'step' => '',
'readonly' => 0,
'disabled' => 0,
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'case_study',
),
),
),
You would do a query for posts based on the radio something like this
// get posts with radio value of 'radio_case_study'
$args = array(
'posts_per_page' => -1,
'post_type' => 'case_study',
'meta_key' => 'case_radio',
'meta_value' => 'radio_case_study'
);
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.