WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] During development of site want to show ALL posts regardless of status (3 posts)

  1. marky_uk
    Member
    Posted 1 year ago #

    Got an interesting query ...

    During build/development of a site, I want all WP users to be able to use the WP-Admin "Status" box to change whether something is draft, approved, published/complete, etc - so out of 200 pages, they know what's finished, still to work on, etc.

    However, on the website I want to show EVERY page and post, regardless of status - so as the site is being built, people can see it growing quickly.

    Then I'll show a box on the front-end website stating the status - "THIS PAGE IS CURRENTLY IN REVIEW" etc.

    I don't want to start hacking around each of my theme template files to change WP_Query to pick up more than is necessary (which I know would be possible but downright ugly!)

    Does anyone know how to do this? Custom Status and Edit Flow don't allow this ....

    Thanks!

    Mark

  2. s_ha_dum
    Member
    Posted 1 year ago #

    Filter posts_where. Run...

    function pwhere_filter($where) {
        var_dump($where);
    }
    add_action('posts_where','pwhere_filter');

    ... and I think you will see what needs to be done. That is a very simple hack that can easily be reversed when you are ready.

  3. marky_uk
    Member
    Posted 1 year ago #

    Hey s_ha_dum

    Brilliant reply, thank you! That's EXACTLY the missing piece of my jigsaw puzzle.

    An example of code in case anyone is following this and wants to see the start of my solution -

    function pwhere_filter($where) {
        global $blog_id;
        $where = str_replace("'private'", "'private' OR wp_".$blog_id."_posts.post_status = 'Draft'", $where);
        //var_dump($where);
        return $where;
      }
      add_action('posts_where','pwhere_filter');

    :-)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.