【问题标题】:Get all Post as per Category and Tag ( from url parameter) in wordpress在wordpress中根据类别和标签(来自url参数)获取所有帖子
【发布时间】:2014-09-23 07:17:06
【问题描述】:

我想要一个自定义页面,我可以在其中根据 Url 参数(猫和标签)获取所有帖子

<a href="localhost/celeb_page.php?cat=38&tag=aamir-khan" >View All Photo of Aamir</a>

注意:cat=38 是我的类别 Photo gallerytag = aamir-khantaxonomy slug

因此,如果有人单击上面的链接,则与aamir khan 相关的照片库帖子将根据其猫 ID 和标签被查看

注意它不是任何自定义帖子,也不是自定义分类。

wrodpress 让我有点困惑

【问题讨论】:

    标签: php wordpress parameters customization


    【解决方案1】:

    我认为以下代码将帮助您获取帖子的类别和标签。您可以从 url 获取类别和标签。

      $category=$_GET["category"];
      $tag=$_GET["tag"];
      global $wp_query;
                $args = array(
                'category__and' => $category, 
                'tag__in' => $tag, //must use tag id for this field
                'posts_per_page' => -1); //get all posts
    
       $posts = get_posts($args);
                foreach ($posts as $post) :
          //do stuff 
             endforeach;
    

    【讨论】:

    • 嘿,谢谢您的回复,但正如我所说的,我想根据我的 URL 传递参数类别 ID 和标签 slug 进行发布
    • 我认为您可以从 url 本身获取类别和标签。
    • 是的,我知道了,它现在可以工作了,实际上我没有从 url 获取类别和标签值......就像我在永久链接上一样,因此它导致了问题..done..它现在工作了。 .感谢您到现在为止的支持
    猜你喜欢
    • 2014-05-12
    • 1970-01-01
    • 2018-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多