Skip to content

Instantly share code, notes, and snippets.

@kylephillips
Created September 15, 2015 21:40
Show Gist options
  • Save kylephillips/f775c134f83c73f8545a to your computer and use it in GitHub Desktop.
Save kylephillips/f775c134f83c73f8545a to your computer and use it in GitHub Desktop.
Apply a filter on the Nested Pages Query
<?php
/**
* Remove Posts from Being Displayed in the Nested Pages List
* @param $args - array of WP_Query arguments
* @see wp-nested-pages/app/Entities/Listing/Listing: Line 274
*/
add_filter('nestedpages_page_listing', 'remove_from_nested_pages');
function remove_from_nested_pages($args)
{
$remove_ids = array(); // Array of Post IDs to exclude
$args['post__not_in'] = $remove_ids;
return $args;
}
@kylephillips
Copy link
Author

Keep in mind, any child posts of excluded posts will also not display.

@DuffmanCC
Copy link

Hi @kylephillips,

I'm trying to pass $args to display only pages child of a parent page and it's not showing anything although the WP_Query object is returning the right array.

add_filter( 'nestedpages_page_listing', function($query_args) {
    $user_id = get_current_user_id();

    $user_meta = get_userdata($user_id);

    $user_roles = $user_meta->roles;

    if (in_array('property_editor', $user_roles)) {
        return $query_args = [
            'post_type' => 'page',
            'post_parent' => 3753
        ];
    }

    return $query_args;
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment