Skip to main content
added 8 characters in body
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

wp_list_pages( $args ) calls get_pages( $args ). You can filter the get_pages() output with a filter on get_pages.

Let’s say you call wp_list_pages() like this:

wp_list_pages(
    array(
        'please_filter_me' => TRUE
    )
);

You can sort the pages now with code like this (not tested):

add_filter( 'get_pages', function( $pages, $args ) {
    // not our query
    if ( empty ( $args['please_filter_me'] ) )
        return $pages;

    $out = $top = array();

    foreach ( $pages as $page )
    {
        if ( get_post_meta( $page->ID, 'my_key', TRUE ) )
            $top[] = $page;
        else
            $out[] = $page;
    }

    return $top + $out;
}, 10, 2 );

wp_list_pages( $args ) calls get_pages( $args ). You can filter the get_pages() output with a filter on get_pages.

Let’s say you call wp_list_pages() like this:

wp_list_pages(
    array(
        'please_filter_me' => TRUE
    )
);

You can sort the pages now with code like this (not tested):

add_filter( 'get_pages', function( $pages, $args ) {
    // not our query
    if ( empty ( $args['please_filter_me'] ) )
        return $pages;

    $out = $top = array();

    foreach ( $pages as $page )
    {
        if ( get_post_meta( $page->ID, 'my_key', TRUE ) )
            $top[] = $page;
        else
            $out[] = $page;
    }

    return $top + $out;
});

wp_list_pages( $args ) calls get_pages( $args ). You can filter the get_pages() output with a filter on get_pages.

Let’s say you call wp_list_pages() like this:

wp_list_pages(
    array(
        'please_filter_me' => TRUE
    )
);

You can sort the pages now with code like this (not tested):

add_filter( 'get_pages', function( $pages, $args ) {
    // not our query
    if ( empty ( $args['please_filter_me'] ) )
        return $pages;

    $out = $top = array();

    foreach ( $pages as $page )
    {
        if ( get_post_meta( $page->ID, 'my_key', TRUE ) )
            $top[] = $page;
        else
            $out[] = $page;
    }

    return $top + $out;
}, 10, 2 );
added 2 characters in body
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

wp_list_pages( $args ) calls get_pages( $args ). You can filter the get_pages() output with a filter on get_pages.

Let’s say you call wp_list_pages() like this:

wp_list_pages(
    array(
        'please_filter_me' => TRUE
    )
);

You can sort the pages now with code like this (not tested):

add_filter( 'get_pages', function( $pages, $args ) {
    // not our query
    if ( empty ( $args['please_filter_me'] ) )
        return $pages;

    $out = $top = array();

    foreach ( $pages as $page )
    {
        if ( get_post_meta( $page->ID, 'my_key', TRUE ) )
            $top[] = $page;
        else
            $out$out[] = $page;
    }

    return $top + $out;
});

wp_list_pages( $args ) calls get_pages( $args ). You can filter the get_pages() output with a filter on get_pages.

Let’s say you call wp_list_pages() like this:

wp_list_pages(
    array(
        'please_filter_me' => TRUE
    )
);

You can sort the pages now with code like this (not tested):

add_filter( 'get_pages', function( $pages, $args ) {
    // not our query
    if ( empty ( $args['please_filter_me'] ) )
        return $pages;

    $out = $top = array();

    foreach ( $pages as $page )
    {
        if ( get_post_meta( $page->ID, 'my_key', TRUE ) )
            $top[] = $page;
        else
            $out = $page;
    }

    return $top + $out;
});

wp_list_pages( $args ) calls get_pages( $args ). You can filter the get_pages() output with a filter on get_pages.

Let’s say you call wp_list_pages() like this:

wp_list_pages(
    array(
        'please_filter_me' => TRUE
    )
);

You can sort the pages now with code like this (not tested):

add_filter( 'get_pages', function( $pages, $args ) {
    // not our query
    if ( empty ( $args['please_filter_me'] ) )
        return $pages;

    $out = $top = array();

    foreach ( $pages as $page )
    {
        if ( get_post_meta( $page->ID, 'my_key', TRUE ) )
            $top[] = $page;
        else
            $out[] = $page;
    }

    return $top + $out;
});
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

wp_list_pages( $args ) calls get_pages( $args ). You can filter the get_pages() output with a filter on get_pages.

Let’s say you call wp_list_pages() like this:

wp_list_pages(
    array(
        'please_filter_me' => TRUE
    )
);

You can sort the pages now with code like this (not tested):

add_filter( 'get_pages', function( $pages, $args ) {
    // not our query
    if ( empty ( $args['please_filter_me'] ) )
        return $pages;

    $out = $top = array();

    foreach ( $pages as $page )
    {
        if ( get_post_meta( $page->ID, 'my_key', TRUE ) )
            $top[] = $page;
        else
            $out = $page;
    }

    return $top + $out;
});