Ok, so I have this custom field wpcf-evento-data-inicio1 generated with the (great) Types plugin.
This is how it stores on db:
OK, so I want to order by this value. I'm doing it by url args, and i can't spot what is wrong... I'm currently doing like this:


I have also tried with meta_value instead of meta_value_num


it outputs like this order:

  1. 1372896000
  2. 1371600000
  3. 1372204800

I just cannot see what is wrong, any ideas? Thank you so much.

(edit: Pls note that this is a archive template (archive-evento.php)

  • I just noticed you first wrote wpcf-evento-data-incio1 and then use wpcf-evento-data-inicio1
    – birgire
    Jun 18, 2013 at 13:24
  • @birgire the first one was a typo. eddited. the one in url is right (double checked) Jun 18, 2013 at 13:25
  • @birgire any ideas? thanks for spotting the error :) Jun 18, 2013 at 13:35
  • I'm not sure you can order by meta this way, you can check out public query vars codex.wordpress.org/WordPress_Query_Vars
    – birgire
    Jun 18, 2013 at 13:40

1 Answer 1


I can't get a meta_key parameter to pass through a GET string at all. Many other parameters that I tested do pass through, though I did not do an exhaustive test, but meta_key does not.

If you want to verify that just add the following to the top of your header.php and inspect the query.

echo '<pre>'; 
var_dump($wp_query); die;
echo '</pre>';

I have never tried to pass that parameter before now but checking the Codex (thanks @birgire), I see that meta_key is listed as a "Private" variable. You cannot pass private variables through an URL, even if the parameters are valid if passed directly to WP_Query via hard-coded PHP.

What you are attempting, seems to be intentionally not allowed. You can only modify the query via an URL using the parameters listed as "Public". Other parameters are ignored, as you can see by inspecting the query as above.

That aside, when I see "ordering" problems like that the first thing I suspect are sticky posts. If you were using WP_Query directly I'd suggest that you add &ignore_sticky_posts=true but I can't get that to pass through GET either.

However, if you really must, you should be able to force this through with a filter on pre_get_posts.

function order_by_meta($qry) {
  if (isset($_GET['meta_key']) && $_GET['meta_key'] == 'wpcf-evento-data-inicio1') {
  • I really appreciate your time and effor to help me on this. I checked codex.wordpress.org/Class_Reference/WP_Query @ "Order & Orderby Parameters" where 'meta_value' and meta_value_num' are possible arguments, but i can't realize what's wrong. Oh, thats a archive template btw.... Jun 18, 2013 at 14:01
  • oh, I see now "Private query vars cannot be used in the URL," Jun 18, 2013 at 14:03
  • Yes, with WP_Query they are valid parameters, but they are not public and so cannot be passed through an URL like you are apparently trying to do.
    – s_ha_dum
    Jun 18, 2013 at 14:03
  • if you could pls edit your awnser with this info i will select it as awnser, to help other users with this same problem Jun 18, 2013 at 14:04
  • My answer already states that meta_key is a "Private" variable.
    – s_ha_dum
    Jun 18, 2013 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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