WP_Query 在传递 'tag' arg 时不起作用
WP_Query isn't working when 'tag' arg is passed
我的第一个问题 :) 我想显示带有特定标签的自定义 post 类型的 post。我正在使用 'tag' => 'slug'
但它不起作用。我不能使用类别,它必须通过标签过滤。这是我的代码:
$args = array(
'numberposts' => 2,
'post_type' => 'poslovi-oglasi',
'tag' => 'javascript',
'orderby' => 'rand',
'posts_per_page' => 2,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'tip_oglasa',
'value' => 'premium',
),
array(
'key' => 'tip_oglasa',
'value' => 'standard',
)
)
);
$the_query = new WP_Query( $args );
echo '<aside id="single-jobs" style="line-height: 100%;">';
if ($the_query->have_posts()): while ($the_query->have_posts()) : $the_query->the_post();
echo '
<div style="float: left; width: 50px;">
<a href="' . get_the_permalink() . '?psl=wgt' . get_the_ID() . '">
<img src="'; $image = get_field('logo_single'); echo $image['url']; echo '" height="50" width="50">
</a>
</div>
<div style="float: right; text-align: left; margin-bottom: 25px; width: 160px;">
<a href="' . get_the_permalink() . '?psl=wgt' . get_the_ID() . '">
<h2><span>' . get_the_title() . '</span></h2>
</a>
<div class="single-jobs-location" style="color: #bbb;">' . get_field('ime_firme') . '</div>
<div class="single-jobs-location">
<a href="http://startit.rs/poslovi/"' . get_field('lokacija_pozicije') . '" style="color: #888;">' . get_field('lokacija_pozicije') . '</a>
</div>
</div>
<div class="clear"></div>';
endwhile; endif;
当我删除标签 'tag' => 'javascript',
时 post 会显示,但所有 post 都是 post 类型,而不是带有特定标签的 post .
请帮忙,谢谢
我找到解决办法了!有人用这个 slug 'oznaka' 为那个 post 类型注册了标签分类法。所以我只是将 'tag' => 'slug'
更改为 'oznaka' => 'slug'
并且它起作用了。
我需要此代码的网站是一个非常复杂的自定义 WordPress 网站,由在我之前从事该网站工作的几位前辈建立。所以我错过了那个小东西,这可能是因为缺乏经验。
多亏了 doublesharp,我知道我走的路很好,所以我继续寻找答案
我的第一个问题 :) 我想显示带有特定标签的自定义 post 类型的 post。我正在使用 'tag' => 'slug'
但它不起作用。我不能使用类别,它必须通过标签过滤。这是我的代码:
$args = array(
'numberposts' => 2,
'post_type' => 'poslovi-oglasi',
'tag' => 'javascript',
'orderby' => 'rand',
'posts_per_page' => 2,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'tip_oglasa',
'value' => 'premium',
),
array(
'key' => 'tip_oglasa',
'value' => 'standard',
)
)
);
$the_query = new WP_Query( $args );
echo '<aside id="single-jobs" style="line-height: 100%;">';
if ($the_query->have_posts()): while ($the_query->have_posts()) : $the_query->the_post();
echo '
<div style="float: left; width: 50px;">
<a href="' . get_the_permalink() . '?psl=wgt' . get_the_ID() . '">
<img src="'; $image = get_field('logo_single'); echo $image['url']; echo '" height="50" width="50">
</a>
</div>
<div style="float: right; text-align: left; margin-bottom: 25px; width: 160px;">
<a href="' . get_the_permalink() . '?psl=wgt' . get_the_ID() . '">
<h2><span>' . get_the_title() . '</span></h2>
</a>
<div class="single-jobs-location" style="color: #bbb;">' . get_field('ime_firme') . '</div>
<div class="single-jobs-location">
<a href="http://startit.rs/poslovi/"' . get_field('lokacija_pozicije') . '" style="color: #888;">' . get_field('lokacija_pozicije') . '</a>
</div>
</div>
<div class="clear"></div>';
endwhile; endif;
当我删除标签 'tag' => 'javascript',
时 post 会显示,但所有 post 都是 post 类型,而不是带有特定标签的 post .
请帮忙,谢谢
我找到解决办法了!有人用这个 slug 'oznaka' 为那个 post 类型注册了标签分类法。所以我只是将 'tag' => 'slug'
更改为 'oznaka' => 'slug'
并且它起作用了。
我需要此代码的网站是一个非常复杂的自定义 WordPress 网站,由在我之前从事该网站工作的几位前辈建立。所以我错过了那个小东西,这可能是因为缺乏经验。
多亏了 doublesharp,我知道我走的路很好,所以我继续寻找答案