Support

Account

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…