Merging multiple wp_query objects

If you just need the posts of each WP_Query object, you can do do something like this: <?php // fetch blogs here $all_posts = array() foreach($blogs as $b) { switch_to_blog($b->blog_id); $query = new WP_Query(/* your args here */); if($query->have_posts()) $all_posts = array_merge($all_posts, $query->posts); // posts are stored in the `posts` property restore_current_blog(); // FYI: this … Read more

Tracing the life of a query

Well you can try and run debug_backtrace(); on your function. For example: function wpse_82183_debug( $query ) { //your query goes here, this is just a basic one if ( $query->is_home() && $query->is_main_query() ) { $query->set( ‘posts_per_page’, 1 ); //magic happens here var_dump(debug_backtrace()); } } add_action( ‘pre_get_posts’, ‘wpse_82183_debug’ ); There are also a number of plugins … Read more

How to place a loop within another loop?

Try this: We declare an incrementer at the top of our outter loop called $popularLoop to keep track of how many popular loops we’ve been through, we assume we’re going to at least hit 1. Inside our Inner Loop (popular) we need to set how many posts per page we’re going to load, multiple that … Read more

WordPress 4.9.5 PHP intermittent warning trim() expects parameter 1 to be string, array given

I ran into this today. It’s a bug. I filed a bug report here: https://core.trac.wordpress.org/ticket/46797 The problem is this line of code: $qv[‘name’] = trim( $qv[‘name’] ); Source: https://github.com/WordPress/wordpress-develop/blob/a0ca5afd8977b5a3857084d9cb1bd345166e2f21/src/wp-includes/class-wp-query.php#L764 A (malicious) user sends a request that looks like: GET /?q=user/password&name[#post_render][]=passthru&name[#type]=markup&name[#markup]=echo ‘Vuln!! patch it Now!’ > vuln.htm; echo ‘Vuln!!’> sites/default/files/vuln.php; echo ‘Vuln!!’> vuln.php; cd sites/default/files/; echo … Read more

Is it possible to select against a post’s parent’s fields with WP_Query?

You should use posts_join and posts_where filters to modify JOIN and WHERE clauses. add_filter( ‘posts_join’ , ‘se333659_posts_join’, 20, 2 ); add_filter( ‘posts_where’ , ‘se333659_posts_where’, 20, 2 ); function se333659_posts_join( $join, $query ) { global $wpdb; if ( isset($query->query_vars[‘_rev_of_publ’]) && $query->query_vars[‘_rev_of_publ’] == ‘1’ ) { $join .= ” LEFT JOIN {$wpdb->posts} AS rev_p ON ({$wpdb->posts}.post_parent = … Read more

Does WordPress generate an automatic page for post formats?

Take a look at get_post_format_link() Here’s a little example that uses get_post_format_link() to show a link to the format’s archive page. You can see something similar to this in action on Justin Tadlock’s site. function get_post_format_archive_link() { return sprintf( ‘<a class=”post-format-archive-link %1$s” href=”https://wordpress.stackexchange.com/questions/39925/%2$s”>%1$s</a>’, get_post_format(), get_post_format_link( get_post_format() ) ); } usage: echo get_post_format_archive_link(); The URL Structure … Read more

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