Support » Plugin: Admin Post Navigation » Filtering the navigation order

  • Resolved jdnn

    (@habannah)


    Hi Scott,

    So glad I found this plugin — it’s so useful! Now I’m just trying to customize the order of the Previous/Next links. I’ve used the filter you provide and I’m able to order posts by post_date, but I can’t seem to order pages by menu_order (I don’t really care what happens with other CPTs)…

    Here’s what I’ve got so far (the portion affecting pages isn’t working):

    function custom_order_apn( $field ) {
    if ( is_page() ) {
        return 'menu_order';
    } else {
        return 'post_date';
    }
    }
    add_filter( 'c2c_admin_post_navigation_orderby', 'custom_order_apn' );

    I hope you can help me figure this out. Thanks very much in advance!

    https://wordpress.org/plugins/admin-post-navigation/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Scott Reilly

    (@coffee2code)

    WordPress & Plugin Developer

    @habannah: Hi Julie,

    You’re pretty much there and probably would have gotten it if I had documented a change made to the ‘c2c_admin_post_navigation_orderby’ filter whereby it can send a second argument that is the post type being navigated.

    I’ve updated the documentation to reflect the change, which will be included in the next release of the plugin.

    Cheers!

    Here’s the code:

    /**
     * Modify how Admin Post Navigation orders posts for navigation by ordering
     * pages by 'menu_order' and posts by 'post_date'.
     *
     * @param string $field     The field used to order posts for navigation.
     * @param string $post_type The post type being navigated.
     * @return string
     */
    function custom_order_apn( $field, $post_type ) {
    	if ( 'page' === $post_type ) {
    		return 'menu_order';
    	} else {
    		return 'post_date';
    	}
    }
    add_filter( 'c2c_admin_post_navigation_orderby', 'custom_order_apn', 10, 2 );

    Sweet! Thanks, Scott! Works like a charm now 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Filtering the navigation order’ is closed to new replies.