简体   繁体   English

来自自定义帖子类型的特定子类别的 Wordpress 查询帖子

[英]Wordpress Query Posts from specific subcategory of Custom Post Type

Okay guys, this one has me somewhere between ripping my hair out and kicking in my monitor.好吧,伙计们,这个让我介于扯掉我的头发和踢我的显示器之间。 It seems no matter what I try, no matter how many times I re-write the query, change terms, change syntax...I get nothing.似乎无论我尝试什么,无论我重新编写查询多少次,更改术语,更改语法......我什么也没得到。 So I have a website I am working on where we have a custom post type of 'Vinyl' for vinyl records of in an online collection the client wants displayed alphabetically, with a category of 'vinyls' inside the custom post type section.所以我有一个我正在开发的网站,我们有一个自定义帖子类型“乙烯基”,用于客户希望按字母顺序显示的在线收藏中的黑胶唱片,在自定义帖子类型部分中有一个“乙烯基”类别。 The client then further wanted to separate things down and create a child category within 'vinyls' called 'vinyl_ae' (Vinyls alphabetically sorted by the first letter A through E).然后,客户进一步希望将事物分开并在“vinyls”中创建一个名为“vinyl_ae”的子类别(Vinyls 按第一个字母 A 到 E 的字母顺序排序)。 Now, I have the issue where I am trying to query any post at all from the vinyl_ae category/sub-category/whatever the hell it is at this point, and NOTHING turns out.现在,我遇到了一个问题,我试图从vinyl_ae 类别/子类别/无论现在是什么情况来查询任何帖子,但没有任何结果。 The only way I get any results at all is to set an else conditional for the if have_posts() statement.我得到任何结果的唯一方法是为 if have_posts() 语句设置 else 条件。 I'll try to include any all data I can here to help sort this mess out.我将尝试在此处包含所有我能找到的数据,以帮助解决这个问题。

  1. Custom post type - name : vinyl自定义帖子类型 - 名称:乙烯基
  2. main category - name : VINYLs, slug : vinyls, ID : 3主要类别 - 名称:乙烯基,弹头:乙烯基,ID:3
  3. child category - name : Vinyl AE, slug : vinyl_ae, ID : 4571子类别 - 名称:Vinyl AE,弹头:vinyl_ae,ID:4571

Screen Shots of all my category and sub-category layouts我所有类别和子类别布局的屏幕截图

Here is my working Code Currently (take in mind I have stripped it down so much tonight there is not much left and I have tried so many different solutions to the point where I am practically copying and pasting based on results others are having)这是我目前的工作代码(请记住,我今晚已经把它精简了很多,剩下的不多了,我尝试了很多不同的解决方案,以至于我实际上是根据其他人的结果进行复制和粘贴)

<section id="main">
<div class="content-holder no-spacing">
    <div class="container">
        <div class="content-inner">
            <div id="ajax" class="records row">

            <?php
            $args = array(
            'post_type' => 'post' ,
            'posts_per_page' => 6,
            'cat'         => '4571',
            'paged' => get_query_var('paged'),
            'post_parent' => $parent); 
            $mv = new WP_Query($args);
            if ( $mv->have_posts() ) { 

            while ( $q->have_posts() ) {

            $serial = get_field('serial');
            $mv->the_post(); ?>

            <div class="serial-num"><?php echo $serial; ?></div>

            <?php } ?>

            <?php } else { ?>
            <em>Things Still Screwy</em>
            <?php } ?>

        </div>
    </div>
</div>

Thank any and all in advance for any help that can be given, I've thrown in the towel here.提前感谢任何可以提供的帮助,我已经认输了。

There is two things that you should consider in your sample code:您应该在示例代码中考虑两件事:

  1. You should set post_type argument to your custom post type vinyl not the post post type.你应该设置post_type参数您的自定义后型vinylpost岗位类型。

  2. If the serial is a field of your post you should call the $mv->the_post();如果serial是您帖子的一个字段,您应该调用$mv->the_post(); line first and after that call the $serial = get_field('serial');第一行和之后调用$serial = get_field('serial'); statement, because before the_post() call, you can't access post's meta data.声明,因为在the_post()调用之前,您无法访问帖子的元数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM