# Using pre_get_posts not working

**URL:** https://discourse.roots.io/t/using-pre-get-posts-not-working/4048
**Category:** sage
**Created:** 2015-06-16T18:03:16Z
**Posts:** 12

## Post 1 by @josephclawrence — 2015-06-16T18:03:16Z

I’m trying to alter the order of posts displayed on a custom taxonomy archive page. I have created a custom taxonomy archive template, which is working fine. I am using the standard method of altering the query on this page, with the following code:

```
function stage_tax_query_modifications( $query ) {
  if( $query->is_main_query() && $query->is_tax('custom-tax') ) {

    $query->set( 'orderby', 'date' );
    $query->set( 'order', 'DESC' );

  } 
}
add_action('pre_get_posts', 'stage_tax_query_modifications');
```

But nothing I enter here (and I have tried a few different valid values for ‘orderby’ and ‘order’) alters the posts at all. I am wondering if it is something to do with the theme wrapper?

Any help appreciated!

---

## Post 2 by @Foxaii — 2015-06-16T18:05:29Z

Where have you defined the function and action?

---

## Post 3 by @josephclawrence — 2015-06-16T18:31:14Z

I have put it in extra.php

---

## Post 4 by @Foxaii — 2015-06-16T19:06:09Z

It’s not the wrapper. You can test in one of the twenty\* themes, but it looks like these changes in 4.0 are the issue: [https://make.wordpress.org/core/2014/08/29/a-more-powerful-order-by-in-wordpress-4-0/](https://make.wordpress.org/core/2014/08/29/a-more-powerful-order-by-in-wordpress-4-0/)

---

## Post 5 by @kalenjohnson — 2015-06-16T19:50:53Z

Are you seeing any errors/warnings? I assume you have `WP_DEBUG` on.

If you’re using Sage 8.\*, then it also looks like you’re missing the Namespace when passing the function name.

---

## Post 6 by @josephclawrence — 2015-06-17T07:11:17Z

No - I tested with 2015 theme and my function works perfectly, so must be something about Sage…

---

## Post 7 by @josephclawrence — 2015-06-17T07:11:51Z

Ah thank you - how do I pass the Namespace?

---

## Post 8 by @josephclawrence — 2015-06-17T07:16:37Z

No worries, got it…thank you!

---

## Post 9 by @evance — 2015-08-04T12:50:59Z

Hey @josephclawrence – could you elaborate how you got things running? Am struggling myself to use a similar function. Thanks!

---

## Post 10 by @josephclawrence — 2015-08-04T13:07:42Z

It was a while ago now, but I think I followed the Namespace guidelines outlined at this link: [https://roots.io/upping-php-requirements-in-your-wordpress-themes-and-plugins/](https://roots.io/upping-php-requirements-in-your-wordpress-themes-and-plugins/)

---

## Post 11 by @evance — 2015-08-04T13:10:38Z

Allright, just found that post too, will try my best!

---

## Post 12 by @dgbrt — 2015-09-13T14:47:52Z

Thanks guys for the help. For future readers not wanting to dig through the doc, here’s the working code :

```
add_action('pre_get_posts', __NAMESPACE__. '\\stage_tax_query_modifications');
```
