Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WordPress获取具有特定分类法的所有帖子_Php_Mysql_Wordpress - Fatal编程技术网

Php WordPress获取具有特定分类法的所有帖子

Php WordPress获取具有特定分类法的所有帖子,php,mysql,wordpress,Php,Mysql,Wordpress,我正在创建一个定制的PHP脚本,它向WordPress添加帖子,并允许您查看/修改帖子 我使用的WordPress主题有特定的post\u类型,以及该类型的特定变量 我可以添加没有任何问题的帖子,但我很难用特定的tax\u输入值查询所有帖子 以下是添加帖子的代码: include('../wp-config.php'); //Get WordPress Config $new_listing = array( 'post_title' => $listing_title,

我正在创建一个定制的PHP脚本,它向WordPress添加帖子,并允许您查看/修改帖子

我使用的WordPress主题有特定的
post\u类型
,以及该类型的特定变量

我可以添加没有任何问题的帖子,但我很难用特定的
tax\u输入值查询所有帖子

以下是添加帖子的代码:

include('../wp-config.php'); //Get WordPress Config
$new_listing = array(
    'post_title'    => $listing_title,
    'post_name'     => str_replace('-', ' ', $listing_title),
    'post_content'  => $listing_description,
    'tax_input'     => array('property-status' => $listing_phase),
    //$listing_phase is the `term_id` number from what I see in the database
    'post_status'   => 'publish',
    'post_type'     => 'property',
    'post_author'   => 1
);
$listing_id = wp_insert_post($new_listing); //Insert the post into the database
add_post_meta($listing_id, 'REAL_HOMES_banner_sub_title', $listing_subtitle);
add_post_meta($listing_id, 'REAL_HOMES_property_address', $listing_address);
add_post_meta($listing_id, 'REAL_HOMES_property_location', $listing_address_lat.','.$listing_address_lng);
add_post_meta($listing_id, 'REAL_HOMES_property_size', $listing_sqare_foot);
add_post_meta($listing_id, 'REAL_HOMES_property_size_postfix', 'Sq Ft');
add_post_meta($listing_id, 'REAL_HOMES_property_bedrooms', $listing_bedrooms);
add_post_meta($listing_id, 'REAL_HOMES_property_bathrooms', $listing_bathrooms);
add_post_meta($listing_id, 'REAL_HOMES_property_garage', $listing_garage);
我需要做什么才能获得具有相同
tax\u输入值的帖子

下面的代码获取所有
属性
,但对于所有
属性状态
值,我只想显示具有特定
属性状态
值的特定
属性:

$postArgs = array('posts_per_page' => 25, 'post_type' => 'property');
$getListings = get_posts($postArgs);
foreach($getListings as $post) : setup_postdata($post);
?>
    <a href="<?=the_permalink()?>" class="deploy-toggle-1"><?=the_title()?></a>
    <div class="content"><p><?=the_content()?></p></div>
<?
endforeach; 
wp_reset_postdata();
$postArgs=array('posts\u per\u page'=>25,'post\u type'=>'属性');
$getListings=get_posts($postArgs);
foreach($getListings as$post):setup\u postdata($post);
?>


一旦找到分类法的Wordpress文档,我就解决了这个问题

工作守则:

$postArgs = array(
            'posts_per_page' => 25,
            'post_type'     => 'property',
            'tax_query' => array(
                array(
                    'taxonomy' => 'property-status', //Tax_Input
                    'field' => 'term_id', //Or Slug
                    'terms' => '48' //Term ID or Slug Name
                )
            )
        );
$getListings = get_posts($postArgs);
foreach($getListings as $post) : setup_postdata($post);
?>
     <a>" class="deploy-toggle-1"><?=the_title()?></a>
     <div class="content"><p><?=the_content()?></p></div>
<?
endforeach;
wp_reset_postdata();
$postArgs=阵列(
“每页帖子数”=>25,
“post_type”=>“property”,
“tax_query”=>数组(
排列(
“分类法”=>“属性状态”//Tax\u输入
'field'=>'term_id'、//或Slug
'terms'=>'48'//术语ID或段塞名称
)
)
);
$getListings=get_posts($postArgs);
foreach($getListings as$post):setup\u postdata($post);
?>
“class=“deploy-toggle-1”>


添加post\u meta()只是我们应该知道的一件事吗?@草莓哦,这是一个WordPress内置函数,我没有创建它!也许你应该在回复之前做一些研究!!是的。你可能是对的。
$listing\u阶段的内容是什么?
?它不全是从税务发布的,而是从术语发布的