Skip to content

Instantly share code, notes, and snippets.

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/c2fefaa3c9fd5c69e7f5b68334e3e915 to your computer and use it in GitHub Desktop.
Save tdrayson/c2fefaa3c9fd5c69e7f5b68334e3e915 to your computer and use it in GitHub Desktop.
If you trying to query the post object field to between 2 CPT's. This condition checks if the repeater is empty or not.
// Add the function to advanced scripts (or code snippet)
// Create a condition in the builder to the section where you want to hide
// Select dynamic data -> php function -> “Check_CPT_Repeater”
// Inside the arguments section add your "cpt_name" and post object "acf_field"
// Set dynamic data == 0 (to hide if no results are returned)
function Check_CPT_Repeater( $cpt_name, $acf_field ){
//WP_Query arguments
$args = array(
'post_type' => array( $cpt_name ),
'meta_query' => array(
array(
'key' => $acf_field,
'value' => get_the_ID(),
'compare' => 'LIKE',
),
),
);
// The Query
$query = new WP_Query( $args );
if ( ! ( $query->have_posts() ) ) {
return 1;
} else {
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment