How to make an archive page displaying posts in a date range

Saving the date in post meta is a slightly more sane approach, the post_date column was not designed with your use case in mind. You may get weird results with dates before the Unix epoch (January 1, 1970). Then it’s just a simple meta_query to load posts between dates, no filter necessary. $start=”1900-01-01″; $end = … Read more

Multiple search queries on one page

You can use pre_get_posts to modify the main query, but you will need to create new queries for the other searches. Use get_query_var(‘s’) to get the search terms and create new WP_Query objects to perform your search. Without more information it is hard to provide much more detail to the answer.

Example Query Posts Showing the Latest Post with the Featured Image

Getting most recent post in WordPress have builtin function named wp_get_recent_posts( $args, $output ). So let’s try with this function to get most recent 5 post $args = array( ‘numberposts’ => 5, ‘offset’ => 0, ‘category’ => 0, ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘suppress_filters’ => true ); OR … Read more

Prevent change with new query_posts()

You shouldn’t be using query_posts() at all. From the documentation: Note: This function will completely override the main query and isn’t intended for use by plugins or themes. Its overly-simplistic approach to modifying the main query can be problematic and should be avoided wherever possible. In most cases, there are better, more performant options for … Read more

Query for posts in 2 taxonomies

According to the Codex, here’s how you would query posts from several taxonomies: ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘videoscategory’, ‘field’ => ‘slug’, ‘terms’ => $custom_term->slug ), array( ‘taxonomy’ => ‘yourothertaxonomy’, ‘field’ => ‘slug’, ‘terms’ => $other_custom_term->slug ) )

Show Posts From Same Category OR Same Tag

You can achieve that with a tax_query with OR relation. See the Taxonomy Parameters section for WP_Query in Codex for the different tax query parameters. $args = array( ‘tax_query’ => array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => array( ‘fruit’ ) ), array( ‘taxonomy’ => ‘post_tag’, ‘field’ => ‘slug’, ‘terms’ … Read more

Inserting Post Using wp_insert_post. How to Fill Yoast Plugin SEO Fields

You can use the update_post_meta function to insert the Yoast Plugin data. Yoast uses 3 post meta keys for each post: _yoast_wpseo_title ( use for SEO title ) _yoast_wpseo_focuskw (For meta keywords ) _yoast_wpseo_metadesc (For meta descriptio ) You can find all these meta key under postmeta table $new_id = wp_update_post($array); update_post_meta( $new_id, ‘_yoast_wpseo_title’, ‘SEO … Read more

query recent posts from several categories

simply add this above your loop $args = array( ‘posts_per_page’ => 10, ‘category__in’ => array( 2, 6 ), //change and add the category ids here ‘orderby’ => ‘date’, ‘order’ => ‘ASC’) query_posts($args); and you can read more about query_posts Parameters http://codex.wordpress.org/Function_Reference/WP_Query#Parameters Update By popular demand 🙂 here is another example to doing the same but … Read more