Note that there are some explanatory texts on larger screens.

plurals
  1. POMore efficient Wordpress-query parsing? (get_posts($query))
    primarykey
    data
    text
    <p>What is the most efficient way (time-wise) to count number of posts returned from a query and parse the posts returned? </p> <p><strong>PART 1:</strong></p> <p>I currently have this code:</p> <pre><code>/* $query = { 'numberposts' = '15', 'queryvar1' = '…', 'queryvar2' = '…'; } */ $lastposts = get_posts($query); // This uses the original query, and will only return 15 results $print['returnedcount'] = count($lastposts); // Uses some resources (+ acceptable time) $query['numberposts'] = "-1"; // Get total results from query $print['totalposts'] = count(get_posts($query)); // Uses lots of resources (+ lots of time) </code></pre> <p>I have no use for the other data this second <code>get_posts($query)</code>-provides me with, how can I speed that up? I only need to count the total number of posts returned by the query (except the <code>numberposts</code>-value. </p> <p><strong>PART 2:</strong></p> <p>The <code>$lastposts</code>-object will be used later to get post data (ID, date, title, comment count, thumbnail and author ID).</p> <p>These datas are inputed into the <code>$print</code>-array like this:</p> <pre><code>foreach ($lastposts as $post){ // ID $print['id'][] = (string)$post-&gt;ID; // Date $print['date'][] = (string)$post-&gt;post_date; // Title $print['title'][] = (string)$post-&gt;post_title; // Comment count $print['comments'][] = (string)$post-&gt;comment_count; // Images $image = wp_get_attachment_image_src(get_post_thumbnail_id($post-&gt;ID), 'medium'); $print['image'][] = (string)$image[0]; $imageRetina = wp_get_attachment_image_src(get_post_thumbnail_id($post-&gt;ID), 'large'); $print['imageretina'][] = (string)$imageRetina[0]; // Author $print['author'][] = (string)$post-&gt;post_author; } </code></pre> <p>Is there a more time-efficient way to do this? I have noticed that the image-actions do take quite some time. </p> <p>Thanks alot!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload