Skip to main content
Tweeted twitter.com/#!/StackWordPress/status/132824595555295234
added 53 characters in body
Source Link

I'm trying to use the search query along with an array of arguments to narrow down search results, but I'm failing horribly. This is what I have so far.

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;          

$query_string = 's=test&category=wordpress'       

$s_array = array(
    'post_type' => 'blog',
    'caller_get_posts' => 1, 
    'paged' => $paged, 
    'meta_query' => array(
        array(
            'key' => 'votes_percent',
            'value' => '50',
            'compare' => '>',
            'type' => 'numeric',
        )
    )
);
$s_query = http_build_query($s_array);
$is_query = '&' . $s_query;
$s_streaming = $query_string . $is_query;  
query_posts($s_streaming);

When echoing out $s_streaming I get

s=test&category=wordpress&post_type=blog&caller_get_posts=1&paged=1&meta_query%5B0%5D%5Bkey%5D=votes_percent&meta_query%5B0%5D%5Bvalue%5D=50&meta_query%5B0%5D%5Bcompare%5D=%3E&meta_query%5B0%5D%5Btype%5D=numeric

If I remove the meta_query keys it works, so I'm guessing that is where my problem resides.

It works fine like this

query_posts($s_array); //just using the array to filter

query_posts($query_string); //just using the search query
//$query_string = 's=test&category=wordpress';

I'm trying to build the string to query, because this fails.

query_posts($query_string . $s_array); //using both

Can anyone point me in the right direction?

I'm trying to use the search query along with an array of arguments to narrow down search results, but I'm failing horribly. This is what I have so far.

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;                
$s_array = array(
    'post_type' => 'blog',
    'caller_get_posts' => 1, 
    'paged' => $paged, 
    'meta_query' => array(
        array(
            'key' => 'votes_percent',
            'value' => '50',
            'compare' => '>',
            'type' => 'numeric',
        )
    )
);
$s_query = http_build_query($s_array);
$is_query = '&' . $s_query;
$s_streaming = $query_string . $is_query;  
query_posts($s_streaming);

When echoing out $s_streaming I get

s=test&category=wordpress&post_type=blog&caller_get_posts=1&paged=1&meta_query%5B0%5D%5Bkey%5D=votes_percent&meta_query%5B0%5D%5Bvalue%5D=50&meta_query%5B0%5D%5Bcompare%5D=%3E&meta_query%5B0%5D%5Btype%5D=numeric

If I remove the meta_query keys it works, so I'm guessing that is where my problem resides.

It works fine like this

query_posts($s_array); //just using the array to filter

query_posts($query_string); //just using the search query
//$query_string = 's=test&category=wordpress';

I'm trying to build the string to query, because this fails.

query_posts($query_string . $s_array); //using both

Can anyone point me in the right direction?

I'm trying to use the search query along with an array of arguments to narrow down search results, but I'm failing horribly. This is what I have so far.

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;          

$query_string = 's=test&category=wordpress'       

$s_array = array(
    'post_type' => 'blog',
    'caller_get_posts' => 1, 
    'paged' => $paged, 
    'meta_query' => array(
        array(
            'key' => 'votes_percent',
            'value' => '50',
            'compare' => '>',
            'type' => 'numeric',
        )
    )
);
$s_query = http_build_query($s_array);
$is_query = '&' . $s_query;
$s_streaming = $query_string . $is_query;  
query_posts($s_streaming);

When echoing out $s_streaming I get

s=test&category=wordpress&post_type=blog&caller_get_posts=1&paged=1&meta_query%5B0%5D%5Bkey%5D=votes_percent&meta_query%5B0%5D%5Bvalue%5D=50&meta_query%5B0%5D%5Bcompare%5D=%3E&meta_query%5B0%5D%5Btype%5D=numeric

If I remove the meta_query keys it works, so I'm guessing that is where my problem resides.

It works fine like this

query_posts($s_array); //just using the array to filter

query_posts($query_string); //just using the search query
//$query_string = 's=test&category=wordpress';

I'm trying to build the string to query, because this fails.

query_posts($query_string . $s_array); //using both

Can anyone point me in the right direction?

added 59 characters in body
Source Link

I'm trying to use the search query along with an array of arguments to narrow down search results, but I'm failing horribly. This is what I have so far.

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;                
$s_array = array(
    'post_type' => 'blog',
    'caller_get_posts' => 1, 
    'paged' => $paged, 
    'meta_query' => array(
        array(
            'key' => 'votes_percent',
            'value' => '50',
            'compare' => '>',
            'type' => 'numeric',
        )
    )
);
$s_query = http_build_query($s_array);
$is_query = '&' . $s_query;
$s_streaming = $query_string . $is_query;  
query_posts($s_streaming);

When echoing out $s_streaming I get

s=test&category=wordpress&post_type=blog&caller_get_posts=1&paged=1&meta_query%5B0%5D%5Bkey%5D=votes_percent&meta_query%5B0%5D%5Bvalue%5D=50&meta_query%5B0%5D%5Bcompare%5D=%3E&meta_query%5B0%5D%5Btype%5D=numeric

If I remove the meta_query keys it works, so I'm guessing that is where my problem resides.

It works fine like this

query_posts($s_array); //just using the array to filter

query_posts($query_string); //just using the search query
//$query_string = 's=test&category=wordpress';

I'm trying to build the string to query, because this fails.

query_posts($query_string . $s_array); //using both

Can anyone point me in the right direction?

I'm trying to use the search query along with an array of arguments to narrow down search results, but I'm failing horribly. This is what I have so far.

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;                
$s_array = array(
    'post_type' => 'blog',
    'caller_get_posts' => 1, 
    'paged' => $paged, 
    'meta_query' => array(
        array(
            'key' => 'votes_percent',
            'value' => '50',
            'compare' => '>',
            'type' => 'numeric',
        )
    )
);
$s_query = http_build_query($s_array);
$is_query = '&' . $s_query;
$s_streaming = $query_string . $is_query;
query_posts($s_streaming);

When echoing out $s_streaming I get

s=test&category=wordpress&post_type=blog&caller_get_posts=1&paged=1&meta_query%5B0%5D%5Bkey%5D=votes_percent&meta_query%5B0%5D%5Bvalue%5D=50&meta_query%5B0%5D%5Bcompare%5D=%3E&meta_query%5B0%5D%5Btype%5D=numeric

If I remove the meta_query keys it works, so I'm guessing that is where my problem resides.

It works fine like this

query_posts($s_array); //just using the array to filter

query_posts($query_string); //just using the search query

I'm trying to build the string to query, because this fails.

query_posts($query_string . $s_array); //using both

Can anyone point me in the right direction?

I'm trying to use the search query along with an array of arguments to narrow down search results, but I'm failing horribly. This is what I have so far.

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;                
$s_array = array(
    'post_type' => 'blog',
    'caller_get_posts' => 1, 
    'paged' => $paged, 
    'meta_query' => array(
        array(
            'key' => 'votes_percent',
            'value' => '50',
            'compare' => '>',
            'type' => 'numeric',
        )
    )
);
$s_query = http_build_query($s_array);
$is_query = '&' . $s_query;
$s_streaming = $query_string . $is_query;  
query_posts($s_streaming);

When echoing out $s_streaming I get

s=test&category=wordpress&post_type=blog&caller_get_posts=1&paged=1&meta_query%5B0%5D%5Bkey%5D=votes_percent&meta_query%5B0%5D%5Bvalue%5D=50&meta_query%5B0%5D%5Bcompare%5D=%3E&meta_query%5B0%5D%5Btype%5D=numeric

If I remove the meta_query keys it works, so I'm guessing that is where my problem resides.

It works fine like this

query_posts($s_array); //just using the array to filter

query_posts($query_string); //just using the search query
//$query_string = 's=test&category=wordpress';

I'm trying to build the string to query, because this fails.

query_posts($query_string . $s_array); //using both

Can anyone point me in the right direction?

Fixing the formatting in the code snippets.
Source Link
John P Bloch
  • 11k
  • 37
  • 46

I'm trying to use the search query along with an array of arguments to narrow down search results, but I'm failing horribly. This is what I have so far.

 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;                
       $s_array = array(
            'post_type' =>=> blog'blog',
            'caller_get_posts' =>=> 1, 
            'paged' =>=> $paged, 
                'meta_query' =>=> array(
                    array(
                        'key' =>=> 'votes_percent',
                        'value' =>=> '50',
                        'compare' =>=> '>''>',
                        'type' =>=> 'numeric',
                )
    )) 
);
 
        $s_query = http_build_query($s_array);
 
        $is_query = '&''&' . $s_query;
 
        $s_streaming = $query_string . $is_query;
 
    query_posts($s_streaming);  

When echoing out $s_streaming I get

s=test&category=wordpress&post_type=blog&caller_get_posts=1&paged=1&meta_query%5B0%5D%5Bkey%5D=votes_percent&meta_query%5B0%5D%5Bvalue%5D=50&meta_query%5B0%5D%5Bcompare%5D=%3E&meta_query%5B0%5D%5Btype%5D=numeric s=test&category=wordpress&post_type=blog&caller_get_posts=1&paged=1&meta_query%5B0%5D%5Bkey%5D=votes_percent&meta_query%5B0%5D%5Bvalue%5D=50&meta_query%5B0%5D%5Bcompare%5D=%3E&meta_query%5B0%5D%5Btype%5D=numeric

If I remove the meta_query keys it works, so I'm guessing that is where my problem resides.

It works fine like this

query_posts($s_array); //just using the array to filter

query_posts($query_string); //just using the search query 

I'm trying to build the string to query, because this fails.

query_posts($query_string . $s_array); //using both 

Can anyone point me in the right direction?

I'm trying to use the search query along with an array of arguments to narrow down search results, but I'm failing horribly. This is what I have so far.

 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;                
       $s_array = array(
            'post_type' => blog,
            'caller_get_posts' => 1, 
            'paged' => $paged, 
                'meta_query' => array(
                    array(
                        'key' => 'votes_percent',
                        'value' => '50',
                        'compare' => '>',
                        'type' => 'numeric',
                    )));
 
        $s_query = http_build_query($s_array);
 
        $is_query = '&' . $s_query;
 
        $s_streaming = $query_string . $is_query;
 
    query_posts($s_streaming); 

When echoing out $s_streaming I get

s=test&category=wordpress&post_type=blog&caller_get_posts=1&paged=1&meta_query%5B0%5D%5Bkey%5D=votes_percent&meta_query%5B0%5D%5Bvalue%5D=50&meta_query%5B0%5D%5Bcompare%5D=%3E&meta_query%5B0%5D%5Btype%5D=numeric 

If I remove the meta_query keys it works, so I'm guessing that is where my problem resides.

It works fine like this

query_posts($s_array); //just using the array to filter

query_posts($query_string); //just using the search query

I'm trying to build the string to query, because this fails.

query_posts($query_string . $s_array); //using both

Can anyone point me in the right direction?

I'm trying to use the search query along with an array of arguments to narrow down search results, but I'm failing horribly. This is what I have so far.

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;                
$s_array = array(
    'post_type' => 'blog',
    'caller_get_posts' => 1, 
    'paged' => $paged, 
    'meta_query' => array(
        array(
            'key' => 'votes_percent',
            'value' => '50',
            'compare' => '>',
            'type' => 'numeric',
        )
    ) 
);
$s_query = http_build_query($s_array);
$is_query = '&' . $s_query;
$s_streaming = $query_string . $is_query;
query_posts($s_streaming); 

When echoing out $s_streaming I get

s=test&category=wordpress&post_type=blog&caller_get_posts=1&paged=1&meta_query%5B0%5D%5Bkey%5D=votes_percent&meta_query%5B0%5D%5Bvalue%5D=50&meta_query%5B0%5D%5Bcompare%5D=%3E&meta_query%5B0%5D%5Btype%5D=numeric

If I remove the meta_query keys it works, so I'm guessing that is where my problem resides.

It works fine like this

query_posts($s_array); //just using the array to filter

query_posts($query_string); //just using the search query 

I'm trying to build the string to query, because this fails.

query_posts($query_string . $s_array); //using both 

Can anyone point me in the right direction?

Source Link
Loading