View related categories in order of posts

You are looping through the posts by category and only inside your loop you get the published date. By that time you cannot change the order anymore, unless you postpone echoing the posts to a second loop, where you order them by date. So, inside your foreach loop you do this: $post_array[$news_query->ID] = $news_query->post_date; This … Read more

Place content inside the Post Loop

Just as the loop starts the action loop_start fires. Once each post is setup as the loop iterates, the_post fires. After the loop has finished, loop_end fires. Each of these actions receives a reference to the queried object if you need to check for context. If you are in control of the theme code it … Read more

Trying to display all posts in a category

I don’t know what you tried so far, but below you have a quick answer to list posts from a caategory by its ID. <?php $args = array( ‘posts_per_page’ => -1, // Will show all posts from the category ‘cat’ => 149, // ID of the category ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, ‘post_type’ => … Read more

How to make a shortcode for my WP_Query Loop? [duplicate]

I´m doing this since last year and i´m getting the shortcodes working: function my_code() { ob_start(); get_template_part(‘loop_logos’); return ob_get_clean(); } add_shortcode( ‘logos’, ‘my_code’ ); where get_template_part loads the file loop_logos.php and logos is the name shortcode [logos]. HINT When I started to do this I used to name all equal to avoid mistakes, Ex: function … Read more

Loop Posts Outside of WordPress Installation

The error is related to a file called Requests.php, that is not a WordPress file. I don’t see an include or require for this file in your code. Eventually you can add this before require, and check for the wp-load.php path define( ‘WP_USE_THEMES’, false ); But, do this, will not solve the error, may you … Read more