Created
October 29, 2018 19:09
-
-
Save mtruitt/35d7222c75e84bf625054b7ab267d3dd to your computer and use it in GitHub Desktop.
Pull posts by serialized ACF field
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 | |
/* Setup custom query to get posts with ACF field for Author | |
* First we need to get the ID and pass this for the meta data | |
* Set the key to the name of the field then compare to like so we pull any that contain it | |
* Use Sprintf ti run through to check against that | |
*/ | |
$attorneyID = get_the_id(); | |
$args = array( | |
'post_type' => 'post', | |
'meta_query' => array( | |
'key' => 'choose_the_author', | |
'compare' => 'LIKE', | |
'value' => sprintf(':"%s";', $attorneyID) | |
), | |
'meta_key' => 'choose_the_author', | |
'order' => 'DESC', | |
'posts_per_page' => -1 | |
); | |
$articles_query = new WP_Query( $args ); | |
if ( $articles_query->have_posts() ) : ?> | |
<div class="attorney-articles attorney-info-section"> | |
<h3>Articles:</h3> | |
<ul id="attorney-articles"> | |
<?php while ( $articles_query->have_posts() ) : $articles_query->the_post(); ?> | |
<li><a href="<?php echo get_permalink(); ?>"><?php echo get_the_title(); ?></a></li> | |
<?php endwhile; ?> | |
</ul> | |
</div> | |
<?php endif; | |
wp_reset_postdata(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment