Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micw/2538b586626fc4bf35476ecf70a15512 to your computer and use it in GitHub Desktop.
Save micw/2538b586626fc4bf35476ecf70a15512 to your computer and use it in GitHub Desktop.
wp-sitemap-page patch
From ac676e08cd4b3df4ad723fc2acef250b49871659 Mon Sep 17 00:00:00 2001
From: Michael Wyraz <michael@wyraz.de>
Date: Thu, 6 Dec 2018 21:50:38 +0100
Subject: [PATCH] Make sort order work for custom post types
---
wp-sitemap-page.php | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/wp-sitemap-page.php b/wp-sitemap-page.php
index 7569b83..d556a2d 100644
--- a/wp-sitemap-page.php
+++ b/wp-sitemap-page.php
@@ -521,7 +521,7 @@ function wsp_wp_sitemap_page_func( $atts, $content=null ) {
$cpt = get_post_type_object( $only_cpt );
if ( !empty($cpt) ) {
- return wsp_return_content_type_cpt_items( $is_title_displayed, $display_nofollow, $cpt, $only_cpt, $wsp_exclude_pages, $sort );
+ return wsp_return_content_type_cpt_items( $is_title_displayed, $display_nofollow, $cpt, $only_cpt, $wsp_exclude_pages, $sort, $order );
}
// check if it's a taxonomy
@@ -915,7 +915,7 @@ function wsp_return_content_type_cpt_lists( $is_title_displayed=true, $display_n
* @param str $sort
* @return str $return
*/
-function wsp_return_content_type_cpt_items( $is_title_displayed=true, $display_nofollow=false, $cpt, $post_type, $wsp_exclude_pages, $sort=null ) {
+function wsp_return_content_type_cpt_items( $is_title_displayed=true, $display_nofollow=false, $cpt, $post_type, $wsp_exclude_pages, $sort=null, $order=null ) {
// init
$return = '';
@@ -934,11 +934,16 @@ function wsp_return_content_type_cpt_items( $is_title_displayed=true, $display_n
$args['exclude'] = $wsp_exclude_pages;
}
- // change the sort order
+ // change the sort criteria
if ($sort!==null) {
$args['orderby'] = $sort;
}
+ // change the sort order
+ if ($order!==null) {
+ $args['order'] = $order;
+ }
+
// Query to get the current custom post type
$posts_cpt = get_posts( $args );
--
2.1.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment