1
特定のカテゴリの投稿をすべて表示するにはfooと特定のタグバーのURLを使用しますか?私にはわからないWordPressカテゴリとタグの両方で投稿を表示するためのURL
Example: site.com/category/foo/tag/bar
または
Example: site.com/posts?category={category-id}&tag={tag-id}
特定のカテゴリの投稿をすべて表示するにはfooと特定のタグバーのURLを使用しますか?私にはわからないWordPressカテゴリとタグの両方で投稿を表示するためのURL
Example: site.com/category/foo/tag/bar
または
Example: site.com/posts?category={category-id}&tag={tag-id}
はこのかどうかのデフォルト機能としてありますが、私はそれを達成する方法など、アイデアを持っています。
あなたは、このためのカスタムテンプレートを作成し、そのテンプレートに
get_query_var()
によって クエリ文字列を取得し、その猫/タグ に属するあなたの投稿を取得するためにWP_Querycat
とtag
引数を使用することができます。ここで
サンプル動作するコードです:
$cat_id = get_query_var('category');
$tag_id = get_query_var('tag');
$args = [
//...
//...
'post_type' => 'post', //<-- Replace it with your custom post_type
'post_status' => 'publish',
'tag_id' => $tag_id, //replace tag_id with tag if you are passing tag slug
'cat ' => $cat_id //replace cat with category_name if your are passing category slug
//...
//...
];
// The Query
$query = new WP_Query($args);
if (!empty($query->posts))
{
//print_r($query->posts);
foreach ($query->posts as $post)
{
//Your filtered post
}
}
は、この情報がお役に立てば幸い!
ありがとうございました –
@SyahnurNizam:あなたの質問を解決したら、私の答えを受け入れてください。 –