• Hi everybody,

    I have this website: https://www.2barch.it

    In the portfolio page: https://www.2barch.it/?page_id=12 I would like to decide a different post order for each category. Unfortunately the plug-in works only for the archive pages of each category, not in the portfolio page.
    Following this topic: https://www.ads-software.com/support/topic/reorder-post-within-categories-with-wp_query?replies=11

    I tried to add this code:

    function filter_join($join){
      global $wp_query, $wpdb;
      $join .= " LEFT JOIN ".$wpdb->prefix."reorder_post_rel ON (".$wpdb->prefix."posts.ID = ".$wpdb->prefix."reorder_post_rel.post_id AND ".$wpdb->prefix."term_relationships.term_taxonomy_id = ".$wpdb->prefix."reorder_post_rel.category_id )";
        return $join;
    }
    
    function edit_posts_orderby($orderby){
      global $wp_query, $wpdb;
      $orderby = " ".$wpdb->prefix."reorder_post_rel.id ";
      return $orderby;
    }
    
    add_filter('posts_join', 'filter_join');
    add_filter('posts_orderby', 'edit_posts_orderby');
    $query = new WP_Query(array(
    	'post_type' => 'your_post_type',
    	...
    ));
    remove_filter('posts_join', 'filter_join');
    remove_filter('posts_orderby', 'edit_posts_orderby');

    and that’s what happen in the portofolio page:

    WordPress errore sul database Unknown column ‘wp12_term_relationships.term_taxonomy_id’ in ‘on clause’ per la query SELECT SQL_CALC_FOUND_ROWS wp12_posts.ID FROM wp12_posts LEFT JOIN wp12_reorder_post_rel ON (wp12_posts.ID = wp12_reorder_post_rel.post_id AND wp12_term_relationships.term_taxonomy_id = wp12_reorder_post_rel.category_id ) WHERE 1=1 AND wp12_posts.post_type = ‘property’ AND (wp12_posts.post_status = ‘publish’ OR wp12_posts.post_author = 1 AND wp12_posts.post_status = ‘private’) ORDER BY wp12_reorder_post_rel.id LIMIT 0, 3 fatta da require(‘D:\home\2barch.it\wp-blog-header.php’), require_once(‘D:\home\2barch.it\wp-includes\template-loader.php’), include(‘D:\home\2barch.it\wp-content\themes\arctic\template-projects-grid.php’), WP_Query->__construct, WP_Query->query, WP_Query->get_posts

    How could I fix this problem?

    thanks a lot,
    Federico

    https://www.ads-software.com/plugins/reorder-post-within-categories/

  • The topic ‘reorder-post-within-categories with wp_query’ is closed to new replies.