Conversation
supportHi, I really like your plugin, thank you very much! I want to display sorted by post title, but it is always sorted from Z-A, no matter if I insert ASC or DESC in the shortcode. Is there a solution for this?
Did some digging in the code and found that for CPT, the order argument wasn’t being passed to the function, only the sort attribute, and wasn’t being used to order resulting in the default value of DESC. Once I passed the $order variable to the function and used it to order, it worked. if ( !empty($cpt) ) { return wsp_return_content_type_cpt_items( $is_title_displayed, $display_nofollow, $cpt, $only_cpt, $wsp_exclude_pages, $sort, $order ); } function wsp_return_content_type_cpt_items( $is_title_displayed=true, $display_nofollow=false, $cpt=”, $post_type=”, $wsp_exclude_pages=”, $sort=null, $order=null ) { …. // change the sort order if ($sort!==null) { $args['orderby'] = $sort; $args['order'] = $order; } } This reply was modified 1 year ago by dshakya .
Thank you for this @dshakya – the reverse order of the results on my CPTs was about to drive me crazy. For those willing to update the plugin code themselves until the original developer corrects this, I’m noting line numbers here for you. All changes are in the file wp-sitemap-page.php – bold here indicates the additions per the previous suggestion. Line 593-594: if ( !empty($cpt) ) { return wsp_return_content_type_cpt_items( $is_title_displayed, $display_nofollow, $cpt, $only_cpt, $wsp_exclude_pages, $sort , $order ); } Line 980: function wsp_return_content_type_cpt_items( $is_title_displayed=true, $display_nofollow=false, $cpt='', $post_type='', $wsp_exclude_pages='', $sort=null , $order=null ) { Starting on line 999: // change the sort order if ($sort!==null) { $args['orderby'] = $sort; $args['order'] = $order; } Once I made all three of these changes and re-uploaded the file to my server, the shortcode used of order="ASC" worked as intended. Looking over the code and logic, this may not be totally correct (I think the conditional on line 1000 should be $sort!==null || $order!==null or maybe separate conditionals…) but I am hoping by us posting these necessary changes, the plugin developer might see this thread, perfect the logic and code, and then release an update including these corrections in the near future.
Did some digging in the code and found that for CPT, the order argument wasn’t being passed to the function, only the sort attribute, and wasn’t being used to order resulting in the default value of DESC. Once I passed the $order variable to the function and used it to order, it worked. if ( !empty($cpt) ) { return wsp_return_content_type_cpt_items( $is_title_displayed, $display_nofollow, $cpt, $only_cpt, $wsp_exclude_pages, $sort, $order ); } function wsp_return_content_type_cpt_items( $is_title_displayed=true, $display_nofollow=false, $cpt=”, $post_type=”, $wsp_exclude_pages=”, $sort=null, $order=null ) { …. // change the sort order if ($sort!==null) { $args['orderby'] = $sort; $args['order'] = $order; } } This reply was modified 1 year ago by dshakya .
Thank you for this @dshakya – the reverse order of the results on my CPTs was about to drive me crazy. For those willing to update the plugin code themselves until the original developer corrects this, I’m noting line numbers here for you. All changes are in the file wp-sitemap-page.php – bold here indicates the additions per the previous suggestion. Line 593-594: if ( !empty($cpt) ) { return wsp_return_content_type_cpt_items( $is_title_displayed, $display_nofollow, $cpt, $only_cpt, $wsp_exclude_pages, $sort , $order ); } Line 980: function wsp_return_content_type_cpt_items( $is_title_displayed=true, $display_nofollow=false, $cpt='', $post_type='', $wsp_exclude_pages='', $sort=null , $order=null ) { Starting on line 999: // change the sort order if ($sort!==null) { $args['orderby'] = $sort; $args['order'] = $order; } Once I made all three of these changes and re-uploaded the file to my server, the shortcode used of order="ASC" worked as intended. Looking over the code and logic, this may not be totally correct (I think the conditional on line 1000 should be $sort!==null || $order!==null or maybe separate conditionals…) but I am hoping by us posting these necessary changes, the plugin developer might see this thread, perfect the logic and code, and then release an update including these corrections in the near future.