Use wp_get_recent_posts with search term

It should just be a matter of setting the ‘s’ argument of wp_get_recent_posts() (or just get_posts()) to the search term: $args = array( ‘numberposts’ => $numberposts, ‘offset’ => $offset, ‘category__not_in’ => array(391), ‘category’ => $category, ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘s’ => $searchterm, ); $recent_posts = wp_get_recent_posts( $args, … Read more

Change recent posts widget title

I had a similar situation. Add the following code to your functions.php and see if it works for you. function my_widget_title($title, $instance, $id_base) { if ( ‘recent-posts’ == $id_base) { return __(‘New Title’); } else { return $title; } } add_filter ( ‘widget_title’ , ‘my_widget_title’, 10, 3); Note: this will change the title of all … Read more

Recent Posts widget without Title

This code will set the title to an empty string if it is set to Recent Posts (Which as you noted, is what the Recent Posts widget will set the title to if it is empty): add_filter( ‘widget_title’, ‘wpse_widget_title’, 10, 3 ); function wpse_widget_title( $title, $instance, $id_base ) { if ( ‘recent-posts’ === $id_base && … Read more

Two posts are loaded instead of one?

The core of the problem is that you set cookies when the content is being accessed, not when it is read. Browsers can try to prefetch content, and your description sound like the browser is prefecthing the “next” link found in the header. From experience, you should avoid setting cookies on the server and prefer … Read more

Grabbing specific content

First of all learn WP_Query class. Answering on questions: (this question) How do I grab the nth element of a content type? eg. always getting the 1st or 5th most recent element from the db. $query = new WP_Query( ‘post_type=special_stuff&posts_per_page=1&paged=5’ ); List item // The Query $the_query = new WP_Query( $args ); // The Loop … Read more

How can I show recent posts from same taxonomy as the post currently being viewed?

Have you tried using get_the_terms()? Quick-and-dirty, from your code example: <?php global $post; $terms = get_the_terms( $post->ID, ‘some-term’ ); foreach ($terms as $category) : ?> <h3>More News From This Category</h3> <ul> <?php $posts = get_posts(‘numberposts=20&category=’. $category->term_id); foreach($posts as $post) : ?> <li><a href=”https://wordpress.stackexchange.com/questions/39455/<?php the_permalink(); ?>”><?php the_title(); ?></a></li> <?php endforeach; ?> <li><strong><a href=”<?php echo get_category_link($category->term_id);?>” title=”View … Read more

What’s the difference between “get_posts” and “wp_get_recent_posts” when used with “setup_postdata”?

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( $args, OBJECT_K … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)