How to get post id of static front page?

WordPress has a few useful options. You can get the homepage ID by using the following: $frontpage_id = get_option( ‘page_on_front’ ); or the blog ID by using: $blog_id = get_option( ‘page_for_posts’ ); Here’s a list of many useful get_option parameters.

How to get an array of post data from wp_query result?

You should read the function reference for WP_Query on the WordPress codex. There you have a lot of examples to look at. If you don’t want to loop over the result set using a while, you could get all posts returned by the query with the WP_Query in the property posts. For example $query = … Read more

wp query to get child pages of current page

You have to change child_of to post_parent and also add post_type => ‘page’: WordPress codex Wp_query Post & Page Parameters <?php $args = array( ‘post_type’ => ‘page’, ‘posts_per_page’ => -1, ‘post_parent’ => $post->ID, ‘order’ => ‘ASC’, ‘orderby’ => ‘menu_order’ ); $parent = new WP_Query( $args ); if ( $parent->have_posts() ) : ?> <?php while ( … Read more

WP_Query with “post_title LIKE ‘something%'”?

I would solve this with a filter on WP_Query. One that detects an extra query variable and uses that as the prefix of the title. add_filter( ‘posts_where’, ‘wpse18703_posts_where’, 10, 2 ); function wpse18703_posts_where( $where, &$wp_query ) { global $wpdb; if ( $wpse18703_title = $wp_query->get( ‘wpse18703_title’ ) ) { $where .= ‘ AND ‘ . $wpdb->posts … Read more

WP_Query by just the id?

any should retrieve any type: $args = array( ‘p’ => 42, // ID of a page, post, or custom type ‘post_type’ => ‘any’ ); $my_posts = new WP_Query($args); Note the description of any in the documentation: ‘any’ – retrieves any type except revisions and types with ‘exclude_from_search’ set to true. For more information, have a … Read more