Last active
December 5, 2018 17:19
-
-
Save frederikrosendahlkaa/2ad88c625db4ea1582f29af2dfc288f7 to your computer and use it in GitHub Desktop.
ACF-VC Integrator - Relationship field hide unpublished/private posts
This file contains 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
<?php | |
add_filter('acfvc_relationship','acfvc_relationship_hide_unpublished_posts',10,3); | |
function acfvc_relationship_hide_unpublished_posts ( $output, $field, $id ) { | |
$new_output = "<ul>"; | |
foreach ( $field["value"] as $key => $value ) { | |
if ( $value->post_status == "publish" ) { | |
$new_output .= '<li><a href="'.get_permalink($value->ID).'" title="'.get_the_title($value->ID).'">'.get_the_title($value->ID).'</a></li>'; | |
} | |
} | |
$new_output .= "</ul>"; | |
return $new_output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment