Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save tdrayson/c2fefaa3c9fd5c69e7f5b68334e3e915 to your computer and use it in GitHub Desktop.

Select an option

Save tdrayson/c2fefaa3c9fd5c69e7f5b68334e3e915 to your computer and use it in GitHub Desktop.

Revisions

  1. tdrayson revised this gist Nov 8, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Conditionally_display CPT_based_on_post_object_field.php
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    // 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 ){

  2. tdrayson revised this gist Nov 8, 2020. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions Conditionally_display CPT_based_on_post_object_field.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,8 @@
    // 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"

    function Check_CPT_Repeater( $cpt_name, $acf_field ){

    //WP_Query arguments
  3. tdrayson revised this gist Nov 5, 2020. No changes.
  4. tdrayson revised this gist Nov 5, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Conditionally_display CPT_based_on_post_object_field.php
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    function get_CPT_NAME( $cpt_name, $acf_field ){
    function Check_CPT_Repeater( $cpt_name, $acf_field ){

    //WP_Query arguments
    $args = array(
  5. tdrayson revised this gist Nov 5, 2020. 2 changed files with 24 additions and 1 deletion.
    1 change: 0 additions & 1 deletion Conditionally
    Original file line number Diff line number Diff line change
    @@ -1 +0,0 @@
    _
    24 changes: 24 additions & 0 deletions Conditionally_display CPT_based_on_post_object_field.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    function get_CPT_NAME( $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;
    }

    }
  6. tdrayson created this gist Nov 5, 2020.
    1 change: 1 addition & 0 deletions Conditionally
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    _