WordPress.org

Ready to get started?Download WordPress

Forums

passing additional variables to a query (2 posts)

  1. doctorb
    Member
    Posted 12 months ago #

    How can we add more arguments to an existing query? Suppose I have in my theme

    if (!$blog_query) $blog_query = $wp_query;
    
    while( $blog_query->have_posts() ) : $blog_query->the_post();

    AND I want to add to the existing qurey two arguments before passing, say

    'orderby' => 'post-title',
    'order' => 'ASC',

    How can I add these to the existing $blog_query ??

  2. vtxyzzy
    Member
    Posted 11 months ago #

    Try using this:

    global $wp_query;
    if (!$blog_query) $blog_query = query_posts(
       array_merge(
          $wp_query->query,
          array('orderby' => 'title', 'order' => 'ASC')
       )
    );

Reply

You must log in to post.

About this Topic