Skip to content

Instantly share code, notes, and snippets.

@tdrayson
Last active October 28, 2020 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdrayson/20d48bcf5045cd4d9633166925a289bc to your computer and use it in GitHub Desktop.
Save tdrayson/20d48bcf5045cd4d9633166925a289bc to your computer and use it in GitHub Desktop.
Conditionally show a section in Oxygen based on if the CPT has posts attached to it via post object field.Links CPT's and display on frontend using post object field - https://gist.github.com/tdrayson/0b915b4d89615ca663f2bd1f03e0f364Add condition
function check_query_field( $cpt_name, $acf_field ){ //Put CPT as function name
//WP_Query arguments
$args = array(
'post_type' => array( $cpt_name ),//CPT NAME Here
'meta_query' => array(
array(
'key' => $acf_field, //ACF FIELD NAME HERE
'value' => get_the_ID(),
'compare' => 'LIKE',
),
),
);
// The Query
$query = new WP_Query( $args );
if ( ! ( $query->have_posts() ) ) {
return 1;
} else {
return 0;
}
}
// Add condition - Dynamic Data -> PHP Function Return Value -> Function name = check_query_field
// In Function Arguments - CPT_NAME, ACF_FIELD_NAME
// Set Dynamic data == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment