Skip to content

Instantly share code, notes, and snippets.

@waviaei
Last active September 3, 2018 02:46
Show Gist options
  • Save waviaei/db6039503158c80e2b73ba456740b042 to your computer and use it in GitHub Desktop.
Save waviaei/db6039503158c80e2b73ba456740b042 to your computer and use it in GitHub Desktop.
Test different patterns of 'post_status' and 'perm' arguments set for query
/**
* Test different patterns of 'post_status' and 'perm' arguments set for query
* publish, pending, draft, auto-draft, future, private, inherit, trash, any
*/
// Add Shortcode
function status_permission_test_shortcode() {
// the query
$args = array(
'post_status' => array( 'publish' ),
//'post_status' => array( 'publish', 'private' ),
//'post_status' => array( 'publish', 'private', 'future' ),
//'post_status' => array( 'pending' ),
//'perm' => 'readable',
//'perm' => 'editable',
);
$query = new WP_Query( $args );
// the loop
if ( $query->have_posts() ) {
$list .= '</ul>';
while ( $query->have_posts() ) {
$query->the_post();
$list .= '<li><b>' . get_the_title() . '</b> (post_status=' . get_post_status() . ')</li>';
}
$list .= '</ul>';
echo $list;
} else {
echo 'not found';
}
/* Restore original Post Data */
wp_reset_postdata();
}
add_shortcode( 'status-permission-test', 'status_permission_test_shortcode' );
<?xml version="1.0" encoding="UTF-8" ?>
<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. -->
<!-- It contains information about your site's posts, pages, comments, categories, and other content. -->
<!-- You may use this file to transfer that content from one site to another. -->
<!-- This file is not intended to serve as a complete backup of your site. -->
<!-- To import this information into a WordPress site follow these steps: -->
<!-- 1. Log in to that site as an administrator. -->
<!-- 2. Go to Tools: Import in the WordPress admin panel. -->
<!-- 3. Install the "WordPress" importer from the list. -->
<!-- 4. Activate & Run Importer. -->
<!-- 5. Upload this file using the form provided on that page. -->
<!-- 6. You will first be asked to map the authors in this export file to users -->
<!-- on the site. For each author, you may choose to map to an -->
<!-- existing user on the site or to create a new user. -->
<!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. -->
<!-- contained in this file into your site. -->
<!-- generator="WordPress/4.9.8" created="2018-09-03 02:44" -->
<rss version="2.0"
xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wp="http://wordpress.org/export/1.2/"
>
<channel>
<title>query test</title>
<link>http://query-test.test</link>
<description>Just another WordPress site</description>
<pubDate>Mon, 03 Sep 2018 02:44:56 +0000</pubDate>
<language>en-US</language>
<wp:wxr_version>1.2</wp:wxr_version>
<wp:base_site_url>http://query-test.test</wp:base_site_url>
<wp:base_blog_url>http://query-test.test</wp:base_blog_url>
<wp:author><wp:author_id>1</wp:author_id><wp:author_login><![CDATA[admin]]></wp:author_login><wp:author_email><![CDATA[[email protected]]]></wp:author_email><wp:author_display_name><![CDATA[admin]]></wp:author_display_name><wp:author_first_name><![CDATA[]]></wp:author_first_name><wp:author_last_name><![CDATA[]]></wp:author_last_name></wp:author>
<wp:category>
<wp:term_id>1</wp:term_id>
<wp:category_nicename><![CDATA[uncategorized]]></wp:category_nicename>
<wp:category_parent><![CDATA[]]></wp:category_parent>
<wp:cat_name><![CDATA[Uncategorized]]></wp:cat_name>
</wp:category>
<wp:term>
<wp:term_id><![CDATA[1]]></wp:term_id>
<wp:term_taxonomy><![CDATA[category]]></wp:term_taxonomy>
<wp:term_slug><![CDATA[uncategorized]]></wp:term_slug>
<wp:term_parent><![CDATA[]]></wp:term_parent>
<wp:term_name><![CDATA[Uncategorized]]></wp:term_name>
</wp:term>
<generator>https://wordpress.org/?v=4.9.8</generator>
<item>
<title>Hello world!</title>
<link>http://query-test.test/hello-world__trashed/</link>
<pubDate>Mon, 03 Sep 2018 01:12:44 +0000</pubDate>
<dc:creator><![CDATA[admin]]></dc:creator>
<guid isPermaLink="false">http://query-test.test/?p=1</guid>
<description></description>
<content:encoded><![CDATA[Welcome to WordPress. This is your first post. Edit or delete it, then start writing!]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>1</wp:post_id>
<wp:post_date><![CDATA[2018-09-03 01:12:44]]></wp:post_date>
<wp:post_date_gmt><![CDATA[2018-09-03 01:12:44]]></wp:post_date_gmt>
<wp:comment_status><![CDATA[open]]></wp:comment_status>
<wp:ping_status><![CDATA[open]]></wp:ping_status>
<wp:post_name><![CDATA[hello-world__trashed]]></wp:post_name>
<wp:status><![CDATA[trash]]></wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type><![CDATA[post]]></wp:post_type>
<wp:post_password><![CDATA[]]></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<category domain="category" nicename="uncategorized"><![CDATA[Uncategorized]]></category>
<wp:postmeta>
<wp:meta_key><![CDATA[_wp_trash_meta_status]]></wp:meta_key>
<wp:meta_value><![CDATA[publish]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_wp_trash_meta_time]]></wp:meta_key>
<wp:meta_value><![CDATA[1535937199]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_wp_desired_post_slug]]></wp:meta_key>
<wp:meta_value><![CDATA[hello-world]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_wp_trash_meta_comments_status]]></wp:meta_key>
<wp:meta_value><![CDATA[a:1:{i:1;s:1:"1";}]]></wp:meta_value>
</wp:postmeta>
<wp:comment>
<wp:comment_id>1</wp:comment_id>
<wp:comment_author><![CDATA[A WordPress Commenter]]></wp:comment_author>
<wp:comment_author_email><![CDATA[[email protected]]]></wp:comment_author_email>
<wp:comment_author_url>https://wordpress.org/</wp:comment_author_url>
<wp:comment_author_IP><![CDATA[]]></wp:comment_author_IP>
<wp:comment_date><![CDATA[2018-09-03 01:12:44]]></wp:comment_date>
<wp:comment_date_gmt><![CDATA[2018-09-03 01:12:44]]></wp:comment_date_gmt>
<wp:comment_content><![CDATA[Hi, this is a comment.
To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
Commenter avatars come from <a href="https://gravatar.com">Gravatar</a>.]]></wp:comment_content>
<wp:comment_approved><![CDATA[post-trashed]]></wp:comment_approved>
<wp:comment_type><![CDATA[]]></wp:comment_type>
<wp:comment_parent>0</wp:comment_parent>
<wp:comment_user_id>0</wp:comment_user_id>
</wp:comment>
</item>
<item>
<title>Sample Page</title>
<link>http://query-test.test/sample-page/</link>
<pubDate>Mon, 03 Sep 2018 01:12:44 +0000</pubDate>
<dc:creator><![CDATA[admin]]></dc:creator>
<guid isPermaLink="false">http://query-test.test/?page_id=2</guid>
<description></description>
<content:encoded><![CDATA[[status-permission-test]]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>2</wp:post_id>
<wp:post_date><![CDATA[2018-09-03 01:12:44]]></wp:post_date>
<wp:post_date_gmt><![CDATA[2018-09-03 01:12:44]]></wp:post_date_gmt>
<wp:comment_status><![CDATA[closed]]></wp:comment_status>
<wp:ping_status><![CDATA[open]]></wp:ping_status>
<wp:post_name><![CDATA[sample-page]]></wp:post_name>
<wp:status><![CDATA[publish]]></wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type><![CDATA[page]]></wp:post_type>
<wp:post_password><![CDATA[]]></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<wp:postmeta>
<wp:meta_key><![CDATA[_wp_page_template]]></wp:meta_key>
<wp:meta_value><![CDATA[default]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_edit_last]]></wp:meta_key>
<wp:meta_value><![CDATA[1]]></wp:meta_value>
</wp:postmeta>
</item>
<item>
<title>Privacy Policy</title>
<link>http://query-test.test/?page_id=3</link>
<pubDate>Mon, 03 Sep 2018 01:12:44 +0000</pubDate>
<dc:creator><![CDATA[admin]]></dc:creator>
<guid isPermaLink="false">http://query-test.test/?page_id=3</guid>
<description></description>
<content:encoded><![CDATA[<h2>Who we are</h2><p>Our website address is: http://query-test.test.</p><h2>What personal data we collect and why we collect it</h2><h3>Comments</h3><p>When visitors leave comments on the site we collect the data shown in the comments form, and also the visitor&#8217;s IP address and browser user agent string to help spam detection.</p><p>An anonymized string created from your email address (also called a hash) may be provided to the Gravatar service to see if you are using it. The Gravatar service privacy policy is available here: https://automattic.com/privacy/. After approval of your comment, your profile picture is visible to the public in the context of your comment.</p><h3>Media</h3><p>If you upload images to the website, you should avoid uploading images with embedded location data (EXIF GPS) included. Visitors to the website can download and extract any location data from images on the website.</p><h3>Contact forms</h3><h3>Cookies</h3><p>If you leave a comment on our site you may opt-in to saving your name, email address and website in cookies. These are for your convenience so that you do not have to fill in your details again when you leave another comment. These cookies will last for one year.</p><p>If you have an account and you log in to this site, we will set a temporary cookie to determine if your browser accepts cookies. This cookie contains no personal data and is discarded when you close your browser.</p><p>When you log in, we will also set up several cookies to save your login information and your screen display choices. Login cookies last for two days, and screen options cookies last for a year. If you select &quot;Remember Me&quot;, your login will persist for two weeks. If you log out of your account, the login cookies will be removed.</p><p>If you edit or publish an article, an additional cookie will be saved in your browser. This cookie includes no personal data and simply indicates the post ID of the article you just edited. It expires after 1 day.</p><h3>Embedded content from other websites</h3><p>Articles on this site may include embedded content (e.g. videos, images, articles, etc.). Embedded content from other websites behaves in the exact same way as if the visitor has visited the other website.</p><p>These websites may collect data about you, use cookies, embed additional third-party tracking, and monitor your interaction with that embedded content, including tracking your interaction with the embedded content if you have an account and are logged in to that website.</p><h3>Analytics</h3><h2>Who we share your data with</h2><h2>How long we retain your data</h2><p>If you leave a comment, the comment and its metadata are retained indefinitely. This is so we can recognize and approve any follow-up comments automatically instead of holding them in a moderation queue.</p><p>For users that register on our website (if any), we also store the personal information they provide in their user profile. All users can see, edit, or delete their personal information at any time (except they cannot change their username). Website administrators can also see and edit that information.</p><h2>What rights you have over your data</h2><p>If you have an account on this site, or have left comments, you can request to receive an exported file of the personal data we hold about you, including any data you have provided to us. You can also request that we erase any personal data we hold about you. This does not include any data we are obliged to keep for administrative, legal, or security purposes.</p><h2>Where we send your data</h2><p>Visitor comments may be checked through an automated spam detection service.</p><h2>Your contact information</h2><h2>Additional information</h2><h3>How we protect your data</h3><h3>What data breach procedures we have in place</h3><h3>What third parties we receive data from</h3><h3>What automated decision making and/or profiling we do with user data</h3><h3>Industry regulatory disclosure requirements</h3>]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>3</wp:post_id>
<wp:post_date><![CDATA[2018-09-03 01:12:44]]></wp:post_date>
<wp:post_date_gmt><![CDATA[2018-09-03 01:12:44]]></wp:post_date_gmt>
<wp:comment_status><![CDATA[closed]]></wp:comment_status>
<wp:ping_status><![CDATA[open]]></wp:ping_status>
<wp:post_name><![CDATA[privacy-policy]]></wp:post_name>
<wp:status><![CDATA[draft]]></wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type><![CDATA[page]]></wp:post_type>
<wp:post_password><![CDATA[]]></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<wp:postmeta>
<wp:meta_key><![CDATA[_wp_page_template]]></wp:meta_key>
<wp:meta_value><![CDATA[default]]></wp:meta_value>
</wp:postmeta>
</item>
<item>
<title>1. Public + Publish post</title>
<link>http://query-test.test/public-publish-post/</link>
<pubDate>Mon, 03 Sep 2018 01:14:11 +0000</pubDate>
<dc:creator><![CDATA[admin]]></dc:creator>
<guid isPermaLink="false">http://query-test.test/?p=6</guid>
<description></description>
<content:encoded><![CDATA[content 1]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>6</wp:post_id>
<wp:post_date><![CDATA[2018-09-03 01:14:11]]></wp:post_date>
<wp:post_date_gmt><![CDATA[2018-09-03 01:14:11]]></wp:post_date_gmt>
<wp:comment_status><![CDATA[open]]></wp:comment_status>
<wp:ping_status><![CDATA[open]]></wp:ping_status>
<wp:post_name><![CDATA[public-publish-post]]></wp:post_name>
<wp:status><![CDATA[publish]]></wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type><![CDATA[post]]></wp:post_type>
<wp:post_password><![CDATA[]]></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<category domain="category" nicename="uncategorized"><![CDATA[Uncategorized]]></category>
<wp:postmeta>
<wp:meta_key><![CDATA[_edit_last]]></wp:meta_key>
<wp:meta_value><![CDATA[1]]></wp:meta_value>
</wp:postmeta>
</item>
<item>
<title>2. Private + Publish post</title>
<link>http://query-test.test/private-publish-post/</link>
<pubDate>Mon, 03 Sep 2018 01:14:34 +0000</pubDate>
<dc:creator><![CDATA[admin]]></dc:creator>
<guid isPermaLink="false">http://query-test.test/?p=8</guid>
<description></description>
<content:encoded><![CDATA[content 2]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>8</wp:post_id>
<wp:post_date><![CDATA[2018-09-03 01:14:34]]></wp:post_date>
<wp:post_date_gmt><![CDATA[2018-09-03 01:14:34]]></wp:post_date_gmt>
<wp:comment_status><![CDATA[open]]></wp:comment_status>
<wp:ping_status><![CDATA[open]]></wp:ping_status>
<wp:post_name><![CDATA[private-publish-post]]></wp:post_name>
<wp:status><![CDATA[private]]></wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type><![CDATA[post]]></wp:post_type>
<wp:post_password><![CDATA[]]></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<category domain="category" nicename="uncategorized"><![CDATA[Uncategorized]]></category>
<wp:postmeta>
<wp:meta_key><![CDATA[_edit_last]]></wp:meta_key>
<wp:meta_value><![CDATA[1]]></wp:meta_value>
</wp:postmeta>
</item>
<item>
<title>3. Password protected + publish post</title>
<link>http://query-test.test/password-protected-publish-post/</link>
<pubDate>Mon, 03 Sep 2018 01:14:58 +0000</pubDate>
<dc:creator><![CDATA[admin]]></dc:creator>
<guid isPermaLink="false">http://query-test.test/?p=10</guid>
<description></description>
<content:encoded><![CDATA[This is password protected. content 3]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>10</wp:post_id>
<wp:post_date><![CDATA[2018-09-03 01:14:58]]></wp:post_date>
<wp:post_date_gmt><![CDATA[2018-09-03 01:14:58]]></wp:post_date_gmt>
<wp:comment_status><![CDATA[open]]></wp:comment_status>
<wp:ping_status><![CDATA[open]]></wp:ping_status>
<wp:post_name><![CDATA[password-protected-publish-post]]></wp:post_name>
<wp:status><![CDATA[publish]]></wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type><![CDATA[post]]></wp:post_type>
<wp:post_password><![CDATA[pass]]></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<category domain="category" nicename="uncategorized"><![CDATA[Uncategorized]]></category>
<wp:postmeta>
<wp:meta_key><![CDATA[_edit_last]]></wp:meta_key>
<wp:meta_value><![CDATA[1]]></wp:meta_value>
</wp:postmeta>
</item>
<item>
<title>4. Draft + unPublished post</title>
<link>http://query-test.test/?p=13</link>
<pubDate>Mon, 03 Sep 2018 01:15:49 +0000</pubDate>
<dc:creator><![CDATA[admin]]></dc:creator>
<guid isPermaLink="false">http://query-test.test/?p=13</guid>
<description></description>
<content:encoded><![CDATA[content 4]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>13</wp:post_id>
<wp:post_date><![CDATA[2018-09-03 01:15:49]]></wp:post_date>
<wp:post_date_gmt><![CDATA[2018-09-03 01:15:49]]></wp:post_date_gmt>
<wp:comment_status><![CDATA[open]]></wp:comment_status>
<wp:ping_status><![CDATA[open]]></wp:ping_status>
<wp:post_name><![CDATA[draft-unpublished-post]]></wp:post_name>
<wp:status><![CDATA[draft]]></wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type><![CDATA[post]]></wp:post_type>
<wp:post_password><![CDATA[]]></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<category domain="category" nicename="uncategorized"><![CDATA[Uncategorized]]></category>
<wp:postmeta>
<wp:meta_key><![CDATA[_edit_last]]></wp:meta_key>
<wp:meta_value><![CDATA[1]]></wp:meta_value>
</wp:postmeta>
</item>
<item>
<title>5. Pending review + not published post</title>
<link>http://query-test.test/?p=15</link>
<pubDate>Mon, 03 Sep 2018 01:16:30 +0000</pubDate>
<dc:creator><![CDATA[admin]]></dc:creator>
<guid isPermaLink="false">http://query-test.test/?p=15</guid>
<description></description>
<content:encoded><![CDATA[content 5]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>15</wp:post_id>
<wp:post_date><![CDATA[2018-09-03 01:16:30]]></wp:post_date>
<wp:post_date_gmt><![CDATA[2018-09-03 01:16:30]]></wp:post_date_gmt>
<wp:comment_status><![CDATA[open]]></wp:comment_status>
<wp:ping_status><![CDATA[open]]></wp:ping_status>
<wp:post_name><![CDATA[]]></wp:post_name>
<wp:status><![CDATA[pending]]></wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type><![CDATA[post]]></wp:post_type>
<wp:post_password><![CDATA[]]></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<category domain="category" nicename="uncategorized"><![CDATA[Uncategorized]]></category>
<wp:postmeta>
<wp:meta_key><![CDATA[_edit_last]]></wp:meta_key>
<wp:meta_value><![CDATA[1]]></wp:meta_value>
</wp:postmeta>
</item>
<item>
<title>6. Scheduled Dec 3 + Scheduled post</title>
<link>http://query-test.test/?p=17</link>
<pubDate>Mon, 03 Dec 2018 01:17:40 +0000</pubDate>
<dc:creator><![CDATA[admin]]></dc:creator>
<guid isPermaLink="false">http://query-test.test/?p=17</guid>
<description></description>
<content:encoded><![CDATA[content 6]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>17</wp:post_id>
<wp:post_date><![CDATA[2018-12-03 01:17:40]]></wp:post_date>
<wp:post_date_gmt><![CDATA[2018-12-03 01:17:40]]></wp:post_date_gmt>
<wp:comment_status><![CDATA[open]]></wp:comment_status>
<wp:ping_status><![CDATA[open]]></wp:ping_status>
<wp:post_name><![CDATA[scheduled-dec-3-scheduled-post]]></wp:post_name>
<wp:status><![CDATA[future]]></wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type><![CDATA[post]]></wp:post_type>
<wp:post_password><![CDATA[]]></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<category domain="category" nicename="uncategorized"><![CDATA[Uncategorized]]></category>
<wp:postmeta>
<wp:meta_key><![CDATA[_edit_last]]></wp:meta_key>
<wp:meta_value><![CDATA[1]]></wp:meta_value>
</wp:postmeta>
</item>
</channel>
</rss>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment