Get post ids from WP_Query?
Try $post_ids = wp_list_pluck( $latest->posts, ‘ID’ ); Read wp_list_pluck
Try $post_ids = wp_list_pluck( $latest->posts, ‘ID’ ); Read wp_list_pluck
Hi @Rob: The reason you can’t figure out how to do it is because it’s not possible, at least not without resorting to SQL. Try adding the following to your theme’s functions.php file: add_filter(‘posts_where’,’yoursite_posts_where’,10,2); function yoursite_posts_where($where,$query) { global $wpdb; $new_where = ” TRIM(IFNULL({$wpdb->postmeta}.meta_value,”))<>” “; if (empty($where)) $where = $new_where; else $where = “{$where} AND {$new_where}”; … Read more
No, it is not possible, and could even be dangerous. Serialised data is an attack vector, and a major performance issue. I strongly recommend you unserialise your data and modify your save routine. Something similar to this should convert your data to the new format: $args = array( ‘post_type’ => ‘my-post-type’, ‘meta_key’ => ‘_coordinates’, ‘posts_per_page’ … Read more
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.
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
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
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
The first several work as you would expect: = equals != does not equal > greater than >= greater than or equal to < less than <= less than or equal to LIKE and NOT LIKE LIKE and NOT LIKE are SQL operators that let you add in wild-card symbols, so you could have a … Read more
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
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