I produced a area using the Adv Custom Fields wordpress plugin which enables the consumer to choose which section the page is under (like groups). On each page Let me display a sidebar which shows a listing of pages with similar section. Cleaning it once a to make use of meta_query and that i do not get any improvements. I'd like to show parents page first if there's a method to get it done. Here's my query:
<ul class="test-menu"> <?php $section = get_field('section'); $args = array( 'meta_query' => array( array( 'key' => 'section', 'value' => $section ) ) ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); ?> <li><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></li> <?php endwhile; ?> <?php wp_reset_query(); ?> </ul>
Appears like you have to specify a publish_key in your query and you're simply missing the compare bit although I am unsure which throw you off :
$args = array( 'post_type' => 'post', 'meta_query' => array( array( 'key' => 'section', 'value' => $section, 'compare' => "=" ) ) );
The publish type can most likely be an assortment for those who have multiple kind of custom posts.