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

When to use WP_query(), query_posts() and pre_get_posts

You are right to say: Never use query_posts anymore pre_get_posts pre_get_posts is a filter, for altering any query. It is most often used to alter only the ‘main query’: add_action(‘pre_get_posts’,’wpse50761_alter_query’); function wpse50761_alter_query($query){ if( $query->is_main_query() ){ //Do something to main query } } (I would also check that is_admin() returns false – though this may be … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)