Tag Info

Hot answers tagged

4

Have a look in wp-includes\default-widgets.php. /** * Recent_Posts widget class * * @since 2.8.0 */ class WP_Widget_Recent_Posts extends WP_Widget { function __construct() { $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your site") ); ...


4

The default Recent Posts Widget code is in includes/default-widgets.php but you should not be hacking Core code. Copy that function to your theme's functions.php, rename it, and create your own customized widget.


3

http://codex.wordpress.org/Function_Reference/get_comments#Parameters your problem is using author_email, you need user_id i just use similar script. <?php $args = array( 'user_id' => $user->ID, 'number' => 10, // how many comments to retrieve 'status' => 'approve' ); $comments = get_comments( $args ...


3

Give it a try works perfect for me what it is doing query get the all the posts with a left jon with comments table so when a post has comment then it also has the comment_date if no comments posted on the post then in result set it will be null so i have merged the comment_date with post_date so which post has the greater date (for comment_date or ...


3

The original author isn't quite right in saying "which is merely the more elegant way to write". set_query_var() will always override the main query, whereas if you actually use: $wp_query->set( 'category__not_in', $excluded ); ... it will work for any instance of query_posts(), such as the recent posts widget.


2

You can exclude posts from the recent posts widget via the widget_posts_args filter: add_filter( 'widget_posts_args', 'exclude_posts_wpse_103570'); function exclude_posts_wpse_103570( $args ){ // post ID's to exclude: $args['post__not_in'] = array( 123, 234, 345 ); return $args; }


2

Don't use the 'helper' methods, they tend to cause more trouble than they're worth. Any time you want to grab posts, be it the latest, the oldest, in a category etc, use a WP_Query loop, here is its standard form: $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); ...


1

If you look at the source of setup_postdata() you'll find that it requires an object ($post), to be passed, not an array. wp_get_recent_posts() (source), by default (for pre 3.1 backwards compatibilty) returns each post as an array. The second, optional argument, that can be passed to wp_get_recent_posts() can prevent this: $posts = wp_get_recent_posts( ...


1

First, don't use query_posts(). Just don't: It should be noted that using this to replace the main query on a page can increase page loading times, in worst case scenarios more than doubling the amount of work needed or more. While easy to use, the function is also prone to confusion and problems later on. See the note further below on caveats ...


1

You can use the wp_trim_excerpt() to get the excerpt of the content. You can use it inside your loop to get the excerpt of each post the string provided to a maximum of 55 words if it is more then a [...] will be added to the end of the string. <?php $recent_posts = wp_get_recent_posts(array('post_type'=>'jokes')); foreach( $recent_posts ...


1

The problem looks to me to be this line: $latest_items = WP_query( 'post_type' = 'ait-dir-item', 'cat=0&posts_per_page=' . $number ); That is very odd. First, you are missing the new keyword. Without it you get an "undefined function" error. Second, with WP_Query, and a number of other functions, you can use a query-string-like function argument, or ...


1

Per @TheDeadMedic, I have adjusted my code. Hopefully it will now work on all non-admin queries. add_action('pre_get_posts', 'wpa_136017' ); function wpa_136017( $wp_query ) { //$wp_query is passed by reference. we don't need to return anything. whatever changes made inside this function will automatically effect the global variable $excluded = ...


1

This is what i would use to exclude categories from the categories widget function widget_categories_args_filter( $cat_args ) { $cat_args['exclude'] = array(1,2,3); return $cat_args; } add_filter( 'widget_categories_args', 'widget_categories_args_filter', 10, 1 ); There are NO filters to exclude categories from the recent posts or recent comments ...



Only top voted, non community-wiki answers of a minimum length are eligible