Display all Post titles with Category and Tag

As suggested in a comment, the best approach here will be to make use of a tax_query. You have much more flexibility and the ability to run more complex queries specially when you are working with more than one taxonomy (in this case category and post_tag). You can try something like this $args = [ … Read more

Sorting not working with get_posts

Hello bro try this will work ! $newsItems2 = get_posts( [ “post_type” => “post”, “post_status” => “publish”, “posts_per_page” => 3, “orderby” => “date”, “order” => “DESC”, “meta_key” => “news__type”, “meta_value” => “general”, ] );

How to create a custom loop ordered by Categories on a Page Template?

Not sure if this is exactly what you’re asking, but it sounds like you’re looking for nested loops. This will list the most recent 5 posts in every category on your site: foreach ( get_terms(‘category’) as $category ) { echo ‘<h2>’.$category->name.'</h2>’; echo ‘<ul>’; foreach ( get_posts( ‘cat=”.$category->term_id ) as $post ) { setup_postdata( $post ); … Read more

Function to get content by ID

Instead of using get_posts, which you would use if you wanted to retrieve multiple posts in a loop, you should use get_post, which only retrieves one post by an ID. There is also a built-in excerpt so you might want to go with retrieving post_excerpt. function get_the_excerpt_id($post_id) { $find = get_post($post_id); $excerpt = $find->post_excerpt; $excerpt … Read more

how to call the category of the post

Well first off, that code’s a mess to read, some formatting would definitely help get you an answer. That said, here’s the documentation on WP_Query and some sample code to boot $args = array( ‘post_status’ => ‘publish’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => ‘your_cat_slug’ ) ) ); $posts = … Read more

get_posts() method and paging is not working

@user702325 Here’s how i got it working fine on localhost: I installed the plugin and set the option Place Pager Automatically in Template on “on“. Then in author.php i modified the original query to add some custom parameters. I added this: global $query_string; // required $posts = query_posts(‘posts_per_page=2’); right between rewind_posts(); and get_template_part( ‘loop’, ‘author’ … Read more