0

スラッグ名 (「最も人気のある」など) を使用して、カテゴリの下にあるすべての投稿を取得したいと考えています。どうすればいいですか?

これは私が試したものですが、失敗しました。

<?php
                    global $post;
                    $id = array();
                    $i=0;
                    $args = array( 'numberposts' => 5, 'category' => "most-popular", 'post_status' => "publish", 'order'=>"ASC");
                    $myposts = get_posts( $args );
                    foreach( $myposts as $post ) :  
                        setup_postdata($post); 
                        $id[$i]=$post->ID;
                        $i=$i+1;
                    endforeach; 

                    $article1= new Article($id[0]); 
                                            $article2= new Article($id[1]); //and so on.
                ?>
4

1 に答える 1

1

おそらく、 をid呼び出して最初のものを取得する必要がありget_category_by_slug( $slug )ます。だから多分このようなもの:

$category = get_category_by_slug( 'most-popular' );
$args = array( 'numberposts' => 5, 'category' => $category->term_id, 'post_status' =>  "publish", 'order'=>"ASC");
于 2013-03-26T14:29:48.647 に答える