WP查询-仅按特定用户发布

时间:2012-11-03 作者:Product Investigation

我有问题。我需要插入此wp查询$cust_loop = new WP_Query( \'author=123\' );但我无法删除$args from$cust\\U loop=新的WP\\U查询($args); And i tried everything like$cust\\U loop=新的WP\\U查询($args,“author=123”);`

我只想按特定用户显示帖子,谢谢:)

<小时>

if($typecount>0) {
    class con_latest_reviews extends WP_Widget {
        function con_latest_reviews() {
            /* Widget settings. */
            $widget_ops = array( \'classname\' => \'Continuum Latest Reviews\', \'description\' => \'Displays a single review type by most recent or highest rated. Add multiple widgets for each review type.\' );
            /* Widget control settings. */
            $control_ops = array( \'width\' => 250, \'height\' => 350, \'id_base\' => \'con_latest_reviews\' );
            /* Create the widget. */
            $this->WP_Widget( \'con_latest_reviews\', \'Continuum Latest Reviews\', $widget_ops, $control_ops );
        }   
        function widget( $args, $instance ) {

            extract( $args );

            /* User-selected settings. */
            $title = apply_filters(\'widget_title\', $instance[\'title\'] );
            $sort = $instance[\'sort\'];
            $reviewtype = $instance[\'reviewtype\'];
            $numreviews = $instance[\'numreviews\'];

            //get review type for More link URL purpose
            $reviewtypeurl = $reviewtype;
            if($reviewtypeurl=="game") $reviewtypeurl="video-game";

            if($sort=="highest-rated") {
                $feedsort="meta_value";
                $metakey="&meta_key=Rating";
            } else {
                $feedsort="date";
                $metakey="";
            } ?>

            <div class="tabdiv reviews <?php echo $reviewtype; ?>">

                <?php

                /* Before widget (defined by themes). */
                echo $before_widget;

                /* Title of widget (before and after defined by themes). */
                if ( $title ) { ?>                  
                    <?php echo str_replace(\'<h2 class="gentesque">\',\'<h2 class="gentesque">\',$before_title); ?>
                        <div class="icon <?php echo $reviewtype; ?>">&nbsp;</div>
                        <?php echo $title; ?>
                    <?php echo $after_title; ?>
                <?php } 

                /* HTML output */
                ?>

                <ul>
                    <?php // setup the query
                    $args=\'&posts_per_page=\'.$numreviews.\'_reviews&order=DESC&orderby=\'.$feedsort.$metakey;                             
                    $cust_loop = new WP_Query($args); 
                    if ($cust_loop->have_posts()) : while ($cust_loop->have_posts()) : $cust_loop->the_post(); $postcount++;
                        // if we\'re sorting by rating and this item does not have a rating, hide it
                        $rating = get_post_meta(get_the_ID(), "Rating", $single = true); 
                        if(($rating && $feedsort=="meta_value") || ($feedsort!="meta_value")) {                                     
                            $ratings = con_setup_rating($rating); //setup the ratings array 
                            ?>
                            <li>                                                                                    

                                <?php con_show_rating($ratings[0], $ratings[1], $ratings[2]); // show the stars or hearts ?>    

                                <a class="post-title" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>                                              

                            </li>

                        <?php } ?>

1 个回复
SO网友:Joseph Leedy

如果只需添加额外的参数,只需将其连接到$args. (作为补充说明:我建议使用args数组,而不是query string方法,因为我发现它更具可读性。)

<?php
....
$args=\'&posts_per_page=\'.$numreviews.\'_reviews&order=DESC&orderby=\'.$feedsort.$metakey.\'&author=123\';
....

结束

相关推荐

使用新的WP-Query()从循环中过滤后期格式;

嗨,我目前正在为我的博客构建一个主题。下面的代码指向最新的帖子(特色帖子)。因为这将有一个不同的风格比所有其他职位。然而我想过滤掉帖子格式:链接使用我在循环中定义的WP查询,因为它给我带来了更多的灵活性。我该怎么做呢? <?php $featured = new WP_Query(); $featured->query(\'showposts=1\'); ?> <?php while ($featured->have_post