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
    // this is the actual manipulation; do whatever you need here
    if($dummy_query->is_page('blog')) $request['category_name'] = 'Blog';
    // and then
    return $request;

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?

  • According to your code, you are trying to display posts that are in the category "Blog", is that correct? Aug 29 '11 at 6:42

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

  • 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? 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? 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 ); Mar 11 '12 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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