Dynamically link to the latest post or simulate request of specific post in page template

You can filter wp_nav_menu_objects and add a new item. Here is a simple plugin doing that: <?php # -*- coding: utf-8 -*- /** * Plugin Name: Latest Post In Menu * Description: Append a link to the latest post to all nav menus called with the argument <code>’add_latest_post’ => TRUE</code>. * Plugin URI: http://wordpress.stackexchange.com/q/59892/73 * … Read more

Querying post from a multisite network

You could use your list of blog ids in this way … $posts = array(); foreach ( $your_list_of_blog_ids as $blog_id ) { switch_to_blog( $blog_id ); $query = new WP_Query( array( ‘post_type’ => ‘any’, ‘posts_per_page’ => 10, ) ); while ( $query->have_posts() ) { $query->next_post(); $posts[] = $query->post; } restore_current_blog(); } Important are switch_to_blog and restore_current_blog. … Read more

Given a WP_Query, how can I get a list of tags?

I don’t think that is possible. The SQL query performed by WP_Query returns only the post objects (and perhaps some metadata), while the tags resides in a different table. When looping through the returned posts in templates you usually put the_tags(); or something similar in your templates, which in turns runs a new database query … Read more

replace the WP_Query class in the main query

Ok so it’s doable but could potentially mess up a few things down the line so it’s at your own risk, but then so is everything 🙂 I’ve been trying to do this in order to use a GeoQuery extension class to order events by distance from some location. The simplest way to do it … Read more

Accessing the post content with WP_Query

First of all, don’t use and abuse the $wp_query global variable. This global should be reserved to the main query only. Use any other variable that will not create conflict. Secondly, don’t use the raw WP_Post properties. These are raw and unfiltered. WP_Query does set up postdata by default which make the use of the … Read more

How do I reorder (pop and push) items from WP_Query?

You could use the Metadata API to retrieve the rw_advertising_position metadata for each post, seperate the ads from the content, and then re-insert the ads at the proper locations: /** * Extracts from an array posts with positional metadata and re-inserts them at the proper * indices. See https://wordpress.stackexchange.com/questions/210493 **/ function wpse_210493_apply_advertising_position( &$posts, $return = … Read more

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