Created
March 23, 2022 07:40
-
-
Save carlaizumibamford/a1aef9aae618d517020b2a182fae3de6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Display post by ID: | |
$query = new WP_Query( array( 'p' => 7 ) ); | |
Display page by ID: | |
$query = new WP_Query( array( 'page_id' => 7 ) ); | |
Show post/page by slug | |
$query = new WP_Query( array( 'name' => 'about-my-life' ) ); | |
Display page by slug: | |
$query = new WP_Query( array( 'pagename' => 'contact' ) ); | |
Display child page using the slug of the parent and the child page, separated by a slash (e.g. ‘parent_slug/child_slug’): | |
$query = new WP_Query( array( 'pagename' => 'contact_us/canada' ) ); | |
Display child pages using parent page ID: | |
$query = new WP_Query( array( 'post_parent' => 93 ) ); | |
Display only top-level pages, exclude all child pages: | |
$query = new WP_Query( array( 'post_parent' => 0 ) ); | |
Display posts whose parent is in an array: | |
$query = new WP_Query( array( 'post_parent__in' => array( 2, 5, 12, 14, 20 ) ) ); | |
Display only the specific posts: | |
$query = new WP_Query( array( 'post_type' => 'page', 'post__in' => array( 2, 5, 12, 14, 20 ) ) ); | |
Display all posts but NOT the specified ones: | |
$query = new WP_Query( array( 'post_type' => 'post', 'post__not_in' => array( 2, 5, 12, 14, 20 ) ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment