Different Results with query(‘s=computer’) vs get_posts(‘s=computer’)?

The default arguments for get_posts() function include ‘numberposts’ => 5. So if you’re querying for a search term that returns more than five (5) results the second query will return a maximum value of 5 unless you pass ‘s=computer&numberposts=-1′ as your query string. The WP_Query object doesn’t have a ‘numberposts’ default, although it is affected … Read more

What should I use, get_posts or wp_query for less CPU load?

I doubt using get_posts() vs WP_Query() would make any meaningful/noticeable difference in CPU load. Ultimately, get_posts() is just a wrapper for WP_Query(), anyway: $get_posts = new WP_Query; return $get_posts->query($r); You would be better served by looking at the efficiency of the queries themselves; but to provide specific assistance there, we would need to see each … Read more

how could I get the pagination as I want to when query posts using get_posts function

Use paginate_links. It is meant to do pretty much just that. Plus, the ordinary pagination functions like next_posts_link (which I think you want instead of next_post_link) do not work reliably with custom queries, but next_post_link and previous_post_link are equally or more troublesome with custom queries. With paginate_links you need to pass quite a bit of … Read more

Getting movie and serial on actor page

Hy, i resolve a problem, a liitle question, how can i get the text if nothing is selected in custom field ( distributie_serial). Ex: no serial for this actor. This is the Code that works. <?php $seriale = get_posts(array(‘post_type’ => ‘serial’, ‘meta_query’ => array( array(‘key’ => ‘distributie_serial’, // name of custom field ‘value’ => ‘”‘ … Read more

Use post__in and post__not_in together?

post__in and post__not_in are mutually exclusive. Note: you cannot combine post__in and post__not_in in the same query. http://codex.wordpress.org/Class_Reference/WP_Query As your question is written, the solution you reject– that of using array_diff— is the obvious answer. If it is true that that solution won’t work you will need a filter on posts_where (probably) that will provide … Read more

Limit number of pages in pagination

Before I start, do not use get_posts for paginated queries. get_posts legally breaks pagination, and does not return the query object. If you need to paginate queries, use WP_Query As for your issue, I really don’t think limiting the total overall amount of posts to only 100 is possible when you involve pagination. The only … Read more

Query only Posts from Both of Two Category?

Just guessing here, but I suspect that query_posts() is not appropriate in this situation. query_posts() should only be used to modify the main query, and the emerging best practice is that query_posts() shouldn’t be used at all, but, instead, replaced by filtering pre_get_posts. Having said all that, I would look into WP_Query and particularly the … Read more

More posts from the current author

This will retrieve the posts of current author when used in the loop. Put the following in your theme functions.php: function my_get_display_author_posts() { global $authordata, $post; $authors_posts = get_posts( array( ‘author’ => $authordata->ID, ‘post__not_in’ => array( $post->ID ) ) ); $output=”<ul>”; foreach ( $authors_posts as $authors_post ) { $output .= ‘<li><a href=”‘ . get_permalink( $authors_post->ID … Read more

Setting pagination for images attached to a post

You could use paginate_links() to paginate the total gallery. This highly depends on your permalink settings. The best would be to check other answers on that topic here on WPSE. Next/Prev post links for attachments. Than there’s also the task to navigate on single attachment display. Default API function/template tag There’s the adjacent_post_link() function that … Read more

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