所有站点的最新帖子(WordPress Multisite)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了所有站点的最新帖子(WordPress Multisite)相关的知识,希望对你有一定的参考价值。
A function to query the 10 most recent posts on a multisite WordPress installation
function recent_mu_posts( $howMany = 10 ) { global $wpdb; global $table_prefix; // get an array of the table names that our posts will be in // we do this by first getting all of our blog ids and then forming the name of the // table and putting it into an array $rows = $wpdb->get_results( "SELECT blog_id from $wpdb->blogs WHERE public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0';" ); if ( $rows ) : foreach ( $rows as $row ) : $blogPostTableNames[$row->blog_id] = $wpdb->get_blog_prefix( $row->blog_id ) . 'posts'; endforeach; # print_r($blogPostTableNames); # debugging code // now we need to do a query to get all the posts from all our blogs // with limits applied $query = ''; $i = 0; foreach ( $blogPostTableNames as $blogId => $tableName ) : if ( $i > 0 ) : $query.= ' UNION '; endif; $query.= " (SELECT ID, post_date, $blogId as `blog_id` FROM $tableName WHERE post_status = 'publish' AND post_type = 'post')"; $i++; endforeach; $query.= " ORDER BY post_date DESC LIMIT 0,$howMany;"; # echo $query; # debugging code $rows = $wpdb->get_results( $query ); // now we need to get each of our posts into an array and return them if ( $rows ) : foreach ( $rows as $row ) : $posts[] = get_blog_post( $row->blog_id, $row->ID ); endforeach; # echo "<pre>"; print_r($posts); echo "</pre>"; exit; # debugging code return $posts; else: return "Error: No Posts found"; endif; else: return "Error: Could not find blogs in the database"; endif; else: return "Error: Could not find blogs"; endif; }
以上是关于所有站点的最新帖子(WordPress Multisite)的主要内容,如果未能解决你的问题,请参考以下文章
Wordpress Yoast 从 XML 站点地图中排除帖子
您可以使用 phpmyadmin 将 wordpress 帖子放到外部站点吗?
如何查询我的 WordPress 博客以列出我的 Vue.js 网站上的最新帖子?
如何从Wordpress管理员替换帖子和页面的所有外部/预览