admin管理员组文章数量:1122846
I am trying to replace 'tag-slug' with a custom field value, so it will automatically pull the tags that match the custom field 'my-tag-slug'
The code below does what I want
<?php if (get_post_meta(get_the_ID(), 'my-tag-slug', true)) { ?><?php echo get_post_meta(get_the_ID(), 'my-tag-slug', true); ?><?php } else { ?><?php } ?>
but how can I put it here:
<?php
$args=array(
'tag' => 'tag-slug',
'showposts'=>5,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo '5 recent Posts with tag1';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
} //if ($my_query)
wp_reset_query(); // Restore global post data stomped by the_post().
?>
thank you for your help
I am trying to replace 'tag-slug' with a custom field value, so it will automatically pull the tags that match the custom field 'my-tag-slug'
The code below does what I want
<?php if (get_post_meta(get_the_ID(), 'my-tag-slug', true)) { ?><?php echo get_post_meta(get_the_ID(), 'my-tag-slug', true); ?><?php } else { ?><?php } ?>
but how can I put it here:
<?php
$args=array(
'tag' => 'tag-slug',
'showposts'=>5,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo '5 recent Posts with tag1';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
} //if ($my_query)
wp_reset_query(); // Restore global post data stomped by the_post().
?>
thank you for your help
Share Improve this question asked Sep 9, 2013 at 19:43 vyperlookvyperlook 1775 silver badges24 bronze badges1 Answer
Reset to default 0first get tag slug from your saved meta key my-tag-slug in a variable
$tag_slug = (isset(get_post_meta(get_the_ID(), 'my-tag-slug', true))) ? get_post_meta(get_the_ID(), 'my-tag-slug', true) : null;
now query posts by $tag_slug replace showposts with posts_per_page
$args = array(
'tag' => $tag_slug,
'posts_per_page' => 5,
'caller_get_posts' => 1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo '5 recent Posts with tag1';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
} //if ($my_query)
wp_reset_query();
本文标签: Use custom field as tag slug
版权声明:本文标题:Use custom field as tag slug 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736303472a1931897.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论