如何将帖子标题作为值传递?

问题描述 投票:0回答:1

我正在尝试将单个帖子的帖子标题作为'terms'的值:

<?php 
    $term = get_the_title();

    query_posts(array( 
        'post_type' => 'referenzen',
        'tax_query' => array(
            array (
                'taxonomy' => 'referenzen-kategorie',
                'field' => 'slug',
                'terms' => '{$term}',
            )
        ),
        'showposts' => 7 
    ) );  
?>

说明:单个帖子标题与自定义帖子类型'referenzen'的某些帖子的术语相对应,并且有多个带有相应术语的帖子,例如:Design&Production->我正在尝试传递单个将标题“设计与生产”发布到“条款” =>“设计与生产”。

php wordpress categories title taxonomy-terms
1个回答
0
投票

尝试此代码。希望它对您有用。

<?php
global $post;
$term = $post->post_name;

query_posts(array( 
    'post_type' => 'referenzen',
    'tax_query' => array(
        array (
            'taxonomy' => 'referenzen-kategorie',
            'field' => 'slug',
            'terms' => array($term),
        )
    ),
    'showposts' => 7 
) );  
?>
© www.soinside.com 2019 - 2024. All rights reserved.