Home › Forums › General Issues › Query posts based on a select list meta › Reply To: Query posts based on a select list meta
Ok, i resolve the problem not to display in the list the title of the current post :
<?php
function sidebar_related() {
$type = get_field( "themes", get_the_ID() );
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'orderby' => 'date',
'post__not_in' => array(get_the_ID()),
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'themes',
'value' => $type
)
),
);
$my_posts = new WP_Query($args); ?>
<?php if ( $my_posts->have_posts() ) : while ( $my_posts->have_posts() ) : $my_posts->the_post(); ?>
<a href="<?php the_permalink(); ?>"><?php the_title() ;?></a>
<?php endwhile; else : ?>
<p><?php _e( 'No Posts To Display.' ); ?></p>
<?php endif;
}
add_shortcode('related-terms', 'sidebar_related');
?>
To complete, anyone has an idea to display my shortcode [related-terms] in the right place ?
I can’t understand why is out of its module…
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc
— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.