Last active
November 8, 2020 11:43
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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