0

I am trying to do is, when a user post something from his account it will directly need to show on homepage on wordpress site. This will be for all user's role. Here i want to build a feed page like LinkedIn. Thanks in advance.

Manvendra Singh
  • 51
  • 1
  • 11

1 Answers1

0

I'm assuming you have some knowledge... You could just add a loop restricted to a specific author... or user by grabbing the user ID. You could do something like this:

<!-- Start page loop here -->
<?php
// 'post_type' => 'any' ... to display all post and custom post type related to the author or user
// You should restrict the number of post, you don't want your site crashing by loading all posts available
// I'm letting your imagination take over
$authID = get_the_author_meta( 'ID' );
$query = new wp_query( array( 'author' => $authID,'post_type' => 'any', 'post_status' => 'publish', 'posts_per_page' => '3' ) );  if ( $query->have_posts() ): ?>
<h4>Discover your feed </h4>
<?php while ( $query->have_posts() ): $query->the_post(); ?>
<!-- Start page template here -->
<div><a aria-label="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
<!-- End page template here -->
<?php endwhile; else: ?>
<h4>Your feed is empty </h4>
<?php endif; ?>
<!-- End page loop here -->

Should be working just tested it.

Regards. Stackoverflow, World Wide Web support x)

amarinediary
  • 4,930
  • 4
  • 27
  • 45
  • Thanks for answering the question, as you say i have to restrict the number of post so i think i need to get only 15 latest post, then how can i do this without passing 'author' in wp_query array? – Manvendra Singh Jun 28 '20 at 05:53
  • You just have to modify the `'posts_per_page' => '3'` parameter to fit your needs. Just put `'posts_per_page' => '15'` should be perfect. Also you should take a look at all parameters available for the WP_query [see this link](https://developer.wordpress.org/reference/classes/wp_query/) understanding and learning is a process, you should take the time. – amarinediary Jun 28 '20 at 11:40
  • I'm not sure I understand the second part of your comment: `then how can i do this without passing 'author' in wp_query array?` What do you mean by that? If you can elaborate. – amarinediary Jun 28 '20 at 11:44
  • i mean to say that if i am fetching 15 latest post then no need to target author in this case..am i right? – Manvendra Singh Jun 29 '20 at 05:39
  • Well all depends on what you want to do, if it's a feed section specific to the user, this is the right way to go. But if you want an all user feed section for sure then you don't need the user ID. – amarinediary Jun 29 '20 at 10:59