WordPress向循环参数添加变量
我有一个自定义的post类型调用“Sectors”,另一个post类型调用“Challenges”。Challenges post类型有一个名为“sectortype”的分类法,它与Sectors具有相同的名称 我在页面上创建了一个名为“single sector.php”的页面,该页面显示了一个循环,其中包含与该部门相关的挑战 当我编写用于显示挑战的循环时,如何将“sectortype”=>“advanced education”设置为变量,以便在其他单扇区页面上工作 这是我为循环所做的WordPress向循环参数添加变量,wordpress,loops,variables,Wordpress,Loops,Variables,我有一个自定义的post类型调用“Sectors”,另一个post类型调用“Challenges”。Challenges post类型有一个名为“sectortype”的分类法,它与Sectors具有相同的名称 我在页面上创建了一个名为“single sector.php”的页面,该页面显示了一个循环,其中包含与该部门相关的挑战 当我编写用于显示挑战的循环时,如何将“sectortype”=>“advanced education”设置为变量,以便在其他单扇区页面上工作 这是我为循环所做的 &l
<?php $challenge_args = array(
'post_type' => 'challenge',
'sectortype' => 'advanced-education', //Need Help Here
);
// create a new instance of WP_Query
$challenge_query = new WP_Query( $challenge_args );
?>
<?php if ( $challenge_query->have_posts() ) : while ($challenge_query->have_posts() ) : $challenge_query->the_post(); // run the loop ?>
通过自定义分类术语获取自定义帖子:
<?php
$terms = get_terms('sectortype');
$challenge_args = array(
'post_type' => 'challenge',
'publish_status' => 'published',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'sectortype',
'field' => 'slug',
'terms' => $terms[0], //whichever term you want to select
),
),
);
// create a new instance of WP_Query
$challenge_query = new WP_Query( $challenge_args );
?>
<?php if ( $challenge_query->have_posts() ) : while ($challenge_query->have_posts() ) : $challenge_query->the_post(); // run the loop ?>
显示在单独的页面中
要在评论中提到的单独页面中显示帖子,您必须执行以下操作:
创建单独的页面链接::(在页面上用作导航项)
按自定义分类术语获取自定义帖子:
<?php
$terms = get_terms('sectortype');
$challenge_args = array(
'post_type' => 'challenge',
'publish_status' => 'published',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'sectortype',
'field' => 'slug',
'terms' => $terms[0], //whichever term you want to select
),
),
);
// create a new instance of WP_Query
$challenge_query = new WP_Query( $challenge_args );
?>
<?php if ( $challenge_query->have_posts() ) : while ($challenge_query->have_posts() ) : $challenge_query->the_post(); // run the loop ?>
显示在单独的页面中
要在评论中提到的单独页面中显示帖子,您必须执行以下操作:
创建单独的页面链接::(在页面上用作导航项)
对于分类法,我有诸如商业、高级教育等类别。因此,通过您提供的编辑(谢谢),可以在正确的页面上显示来自给定分类法的帖子,而无需为每个帖子创建新页面。对于分类法,我有诸如商业、高级教育等类别。因此,通过您提供的编辑(谢谢)这应该在正确的页面上显示来自给定分类法的帖子,而不必为每个帖子创建新页面?