php - Sort grouped (by type) search results by date? wp -


i'm trying sort , split/group search results date order. have added sort post type functions already. posts in misc order, whist dates have been removed page results.

thank if can me!

tried methods below split posts/pages titles:

wordpress group post type on search page , https://wordpress.stackexchange.com/questions/14881/seperating-custom-post-search-results

if it's not possible both, i'd able sort date page results last.

functions.php:

<?php  if ( function_exists('register_sidebar') )  register_sidebar(array( 'name' => 'sidebar1', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<div class="title">', 'after_title' => '</div>',));  register_sidebar(array( 'name' => 'sidebar2', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<div class="title">', 'after_title' => '</div>',));     function class_tag_cloud($tags) {     $tags = preg_replace_callback("|(class='tag-link-[0-9]+)'(.*?)(style='font-size: )([0-9]+)(.*?)(pt;')|",             create_function(                 '$match',                 '$size=$match[4]-7; return "class=\'tags-{$size}\'{$match[2]}";'             ),             $tags);     return $tags; }  function custom_posts_join( $join, $query ) {     global $wpdb;      //* if main query , search...     if( is_main_query() && is_search() )     {         //* join term_relationships, term_taxonomy, , terms current sql clause         $join .= "         left join          (              {$wpdb->term_relationships}             inner join                  {$wpdb->term_taxonomy} on {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id              inner join                  {$wpdb->terms} on {$wpdb->terms}.term_id = {$wpdb->term_taxonomy}.term_id          )          on {$wpdb->posts}.id = {$wpdb->term_relationships}.object_id ";     }      return $join; } add_filter( 'posts_join', 'custom_posts_join', 10, 2 );  function custom_posts_where( $where, $query ) {     global $wpdb;      if( is_main_query() && is_search() )     {         //* additional clause user         $user_where = get_user_posts_where();          $where .= " or (                         {$wpdb->term_taxonomy}.taxonomy in( 'category', 'post_tag' )                          ,                         {$wpdb->terms}.name '%" . esc_sql( get_query_var( 's' ) ) . "%'                         {$user_where}                     )";     }      return $where; } add_filter( 'posts_where', 'custom_posts_where', 10, 2 );  /**  * clause dependent on current user's status.  *  * @uses get_current_user_id()  * @link http://codex.wordpress.org/function_reference/get_current_user_id  *   * @return string user clause.  */ function get_user_posts_where() {     global $wpdb;      $user_id = get_current_user_id();     $sql     = '';     $status  = array( "'publish'" );      if( 0 !== $user_id )     {         $status[] = "'private'";          $sql .= " , {$wpdb->posts}.post_author = " . absint( $user_id );     }      $sql .= " , {$wpdb->posts}.post_status in( " . implode( ',', $status ) . " ) ";      return $sql; }   add_action('wp_tag_cloud', 'class_tag_cloud'); add_filter( 'wp_feed_cache_transient_lifetime', create_function('$a', 'return 1500;') ); add_theme_support( 'post-thumbnails' );   function remove_cssjs_query_string( $src ) {  if( strpos( $src, '?ver=' ) )  $src = remove_query_arg( 'ver', $src );  return $src; }  function custom_posts_groupby( $groupby, $query ) {     global $wpdb;      //* if main query , search...     if( is_main_query() && is_search() )     {         //* assign groupby         $groupby = "{$wpdb->posts}.id";     }      return $groupby; } add_filter( 'posts_groupby', 'custom_posts_groupby', 10, 2 );  add_filter( 'style_loader_src', 'remove_cssjs_query_string', 10, 2 ); add_filter( 'script_loader_src', 'remove_cssjs_query_string', 10, 2 ); ?> 

search.php:

<?php get_sidebar(); ?>   <div id="content">  <div class="article"> <?php $wp_query->query_vars["posts_per_page"] = 50; $wp_query->get_posts(); $args = array(     'orderby' => 'date',     'order'   => 'desc', ); $query = new wp_query( $args ); ?>   <?php if ( have_posts() ) : ?>                 <?php                 global $wp_query;                 $total_results = $wp_query->found_posts;                 ?>                 <?php printf( __( 'search results for: %s', 'shape' ), '<span>' . get_search_query() . '</span>' ); ?>                 <br/><br/>                   <?php /* start loop */ ?>                 <?php while ( have_posts() ) : the_post(); ?>          <?php  if ("page" != get_post_type()){ ?>         <div class="searchresultsdate">               <?php the_time('m j, y'); ?>                 </div> <?php   } ?><div class="searchresults"><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>                  <?php endwhile; ?>   </div>    <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }   else { ?>  <div class="right"><?php next_posts_link('next page &raquo;') ?></div>  <div class="left"><?php previous_posts_link('&laquo; previous page') ?></div>  <?php } ?>   <br><br><br>   <?php else : ?>    <div class="posttitle">nothing found. try else?</div>  page doesn't exist    <?php endif; ?>    <?php get_footer(); ?> 


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -