modify where clause on get_pages() query (3 posts)

  1. Daniel Watrous
    Posted 6 years ago #


    I want to modify a plugin to return posts of post_type="page" based on an inequality on a meta value. I'm accomplishing this with posts right now using the following:

    add_filter ('posts_where', 'my_where_function');

    function my_where_function ($where)
    global $wp_query, $wpdb;
    $user_value = get_current_user_value ();
    return $where . " AND (meta_value IS NULL OR meta_value <= $user_value)";

    I've found that the function get_pages() in wp-includes/post.php is generating the where clause for listing the pages and I'm not sure what the best route is to create a plugin that will modify that where clause.

    Thanks in advance.

  2. Daniel Watrous
    Posted 6 years ago #

    Hello again,

    This plugin overrides the get_pages() function:

    I could do that, but it would require a change to post-template.php, which currently calls get_pages(). Is there some way to modify the query in get_pages as a plugin that won't require modification to standard wordpress code?

  3. Daniel Watrous
    Posted 6 years ago #

    Well, I ended up creating a widget as an alternative to the default "Pages" widget which has the functionality. That's not as elegant a solution I was hoping for, but I can't see any way around the get_pages function since I can't query based on an inequality of one meta_key/value.

    Here are the pages that helped me create the widget:

    Best of luck to others with a similar problem.

Topic Closed

This topic has been closed to new replies.

About this Topic