0

I would like to show all the posts of a post format on top of the default wp query and show all the other post formats below them (in the same query) using pre_get_posts. Please note that I need to sort the post formats on top by a custom field.


function mysearch( $query ) {
if ( $query->is_main_query() ) {
  if ( isset( $_GET['showtop'] ) ) {
  $showtop = sanitize_text_field($_GET['showtop']);
  if ($showtop == "image") { $query->set( 'post_format', 'post-format-image' ); }
  elseif ($showtop == "video") { $query->set( 'post_format', 'post-format-video' ); }
  }
}
}
add_action( 'pre_get_posts', 'mysearch' );

Should I merge it with another query? What's the best approach? Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.