Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to get a Page to display a custom query using the snippet posted here. The following is in my functions.php:

function alter_the_query($request) {
    $dummy_query = new WP_Query();  // the query isn't run if we don't pass any query vars
    $dummy_query->parse_query($request);
    // this is the actual manipulation; do whatever you need here
    if($dummy_query->is_page('blog')) $request['category_name'] = 'Blog';
    // and then
    return $request;
}
add_filter('request','alter_the_query');

The page called "Blog" has a basic loop inside- so it should be displaying whatever WP_Query tells it to. However, it is only displaying the Page content- which should have been ignored.

I can't seem to find a reference that explains the properties of the $request object, so I'm not sure what I should do to make this snippet work. Any ideas?

share|improve this question
    
According to your code, you are trying to display posts that are in the category "Blog", is that correct? –  Manny Fleurmond Aug 29 '11 at 6:42
add comment

1 Answer 1

Inside your function, simply do a var_dump of the $request object to reveal its properties.

share|improve this answer
    
Thanks, I updated the question name to elicit suggestions about how to actually make the function work. But incidentally, what's a safe way to echo the results of the var_dump? –  Isaac Lubow Jul 27 '11 at 4:40
    
yeah...wasn't sure this was too helpful, but this would be a good step to get started. The var_dump would just allow you to see the props of the object. Just dump it once to see what's in the object. Then work from there. This is more of a troubleshooting step than a full solution. –  tollmanz Jul 27 '11 at 4:46
    
If I do $vardump = var_dump($request); in the function, echoing $vardump on the page yields nothing. How can I check this value? –  Isaac Lubow Jul 27 '11 at 8:01
    
var_dump just prints to screen, it doesn't return anything. If you wanted to inspect the request inside a variable you'd have to use var_export - ie, $vardump = var_export( $request, true ); –  goldenapples Mar 11 '12 at 22:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.