繁体   English   中英

变量为 wp_query 中的 Post_type - Wordpress

[英]variable as Post_type in wp_query - Wordpress

我有一个关于Wordpress和选择性帖子类型选择的问题。

我正在构建一个模板,但我正在尝试使用 ACF 制作一个功能,当有人制作页面时,他们可以选择他们想要在此页面上显示的帖子类型。

我做了一个变量,其中包含以下内容:

$p = the_field('post_typer');

当用户创建页面并选择他想要显示的帖子类型时,此变量会获取他的值。

 $p = the_field('post_typer');

    // WP_Query arguments
    $args = array(
        'post_type' =>  $p,
);

我想知道为什么这不起作用:

'post_type' =>  $p,

请帮忙

根据您拥有的字段类型,您应该执行 get_field

$p = get_field('post_typer');

// WP_Query arguments
$args = array(
    'post_type' =>  $p,
);

https://www.advancedcustomfields.com/resources/get_field/

这对我有用:

        <?php 
        $tipo_post = get_field('tipo_de_post');
        $city_post = get_field('ciudad_npc');

        $loop = new WP_Query( 
              array( 
                'post_type' => $tipo_post, 
                'category_name' => $city_post, 
                'posts_per_page' => 700 
              )); 
          while ( $loop->have_posts() ) : $loop->the_post(); ?>
              <li class="td-nombre text-left align-middle"><a href="<?php the_permalink(); ?>"><?php the_field('nombre'); ?></a></li>
        <?php endwhile; ?>   

暂无
暂无

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

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