admin管理员组文章数量:1429243
I need help looping through a simple php code. What I'm trying to achieve is the following:
Start Loop
Look for all the posts
Add the author first & last name as a tag (links to /tag/firstName-lastName)
Once clicked on the tag, take me to the author page with all their posts
end loop
I'm writing all this in single.php (I'm aware it only effects the page I open and doesn't effect all the blogs)
My Code so far;
<?php
$post_id = get_the_ID();
$queried_post = get_post($post_id);
$user_info = get_userdata($post->the_author);
$first = $user_info->last_name;
wp_set_post_tags( $post_id, $first, true );
?>
I need help looping through a simple php code. What I'm trying to achieve is the following:
Start Loop
Look for all the posts
Add the author first & last name as a tag (links to /tag/firstName-lastName)
Once clicked on the tag, take me to the author page with all their posts
end loop
I'm writing all this in single.php (I'm aware it only effects the page I open and doesn't effect all the blogs)
My Code so far;
<?php
$post_id = get_the_ID();
$queried_post = get_post($post_id);
$user_info = get_userdata($post->the_author);
$first = $user_info->last_name;
wp_set_post_tags( $post_id, $first, true );
?>
Share
Improve this question
edited May 9, 2019 at 12:57
ROCKETS
asked May 8, 2019 at 20:02
ROCKETSROCKETS
33 bronze badges
6
|
Show 1 more comment
2 Answers
Reset to default 0$args = array(
'posts_per_page' => -1,
'post_type' => 'post',
);
$the_query = new WP_Query( $args );
If you set the posts_per_page to -1 it will return all posts. Then you can loop through and do what you want with the single post.
while ( $the_query->have_posts() ) {
echo get_the_author_meta( );//I have NOT used this so you should look into it.
}
Theses links will help you understand the attributes on the_post. https://codex.wordpress/Class_Reference/WP_Post https://developer.wordpress/reference/functions/get_permalink/
You have no 'loop' to loop through the data that is returned by the query.
Take a look at The Loop information in the Codex - lots of examples there (as well as 'the loop' info in the googles/bings/ducks). https://codex.wordpress/The_Loop
本文标签: functionshow to loop through blog posts in php
版权声明:本文标题:functions - how to loop through blog posts in php 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745509644a2661408.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$first
, once from$first
and$last
. You can not use variables wrapped with'
. Look at recent comments – nmr Commented May 9, 2019 at 10:22