从 Wordpress 多站点网络中的另一个站点获取特定类别中的帖子

问题描述

  • 我正在使用此代码wordpress站点安装中从另一个站点的特定类别中提取帖子。但它正在输出所有帖子,而不是按指定类别过滤。任何想法我缺少什么?切换后将忽略类别,尊重数量和顺序。感谢您的帮助。
global $switched;
switch_to_blog(4); //switched to 4

// Get latest Post
$latest_posts = get_posts('category=-28&numberposts=6&orderby=post_name&order=DSC');
$cnt =0;?> 
    <?PHP foreach($latest_posts as $post) : setup_postdata($post);?>

            <?PHP 
            
                // do something
               echo('<div style="position:relative;padding:20px;margin-bottom:20px;background:rgb(249,249,249) url(https://cra.org/crn/wp-content/uploads/sites/7/2016/01/cerp-back-faint.png) no-repeat right bottom;
         border-top: 2px solid #1b806e;
        ">');
            
            echo('<h4 style="font-size:16px;margin:5px 0 5px 0;"><a style="color:#1b806e!important;text-decoration:none" href="');
            the_permalink();
            echo('" title="');
            the_title_attribute();
            echo('">');
            the_title();
            echo('</a></h4>');
            if( get_post_meta($post->ID,'byline',true) ) {
            echo ('<em>By ');
            echo get_post_meta($post->ID,true);
            echo ('</em>');
            }
            if (has_post_thumbnail( $post->ID ) ) {
             $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ),'single-post-thumbnail' ); 
             echo '<a href="'; the_permalink(); echo '" title="'; the_title_attribute(); echo '">';
             echo '<img style="padding:1em" align="right" width="100" src="' . $image[0] . '">';
             echo '</a>';
            }
            the_excerpt();
                // read more button
                echo '<small><a style="font-size: 10px !important;padding: 6px 10px;margin: 0 1px 1px 0;border-style: solid;border-width: 1px;border-color: #eee;text-decoration: none;color: #f9f9f9;background: #75accb;text-transform: uppercase;border-radius: 20px;" href="';
                the_permalink();
                echo '" title="';
                the_title_attribute();
                echo '">Read More</a></small>';
                
                                                                
        ?>                                          
        
        </div>


     <?PHP endforeach ; ?>

<?PHP restore_current_blog(); //switched back to main site ?>   

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)