Support » Plugin: Simple Custom Post Order » Functions based on same category not work

  • Resolved wp-patrick

    (@wp-patrick)


    When I use
    previous_post_link( '&laquo; %link', '%title', true, '', 'category' ); ?> | <?php next_post_link( '%link &raquo;', '%title', true, '', 'category' );
    in my custom theme, then the parameter true/category was not working, because your plugin override the where filters and do not pay attention to this parameters.

    I override these functions in my function.php so the prev/next_post_link functions are working (and also are ordered by the menu_order. Hope you can implement it to your plugin.

    function ify_prevnext_post_join(){
        global $post, $wpdb;
        return " INNER JOIN $wpdb->term_relationships AS tr 
        ON p.ID = tr.object_id 
           INNER JOIN $wpdb->term_taxonomy tt 
        ON tr.term_taxonomy_id = tt.term_taxonomy_id ";
    }
    add_filter('get_previous_post_join', 'ify_prevnext_post_join');
    add_filter('get_next_post_join', 'ify_prevnext_post_join');
     function ify_previous_post_where() {
        global $post, $wpdb;
        $cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids'));
        $posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ") "; 
    	return $wpdb->prepare( "WHERE p.menu_order < %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_cats_sql ", $post->menu_order, $post->post_type);
    }
    add_filter( 'get_previous_post_where', 'ify_previous_post_where' );
    function ify_next_post_where() {
        global $post, $wpdb;
        $cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids'));
        $posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ") "; 
    	return $wpdb->prepare( "WHERE p.menu_order > %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_cats_sql ", $post->menu_order, $post->post_type);
    }
    add_filter( 'get_next_post_where', 'ify_next_post_where' );
    function ify_previous_post_sort() {
    	return "ORDER BY p.menu_order desc LIMIT 1";
    }
    add_filter( 'get_previous_post_sort', 'ify_previous_post_sort' );
    function ify_next_post_sort() {
    	return "ORDER BY p.menu_order asc LIMIT 1";
    }
    add_filter( 'get_next_post_sort', 'ify_next_post_sort' );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Functions based on same category not work’ is closed to new replies.