Skip to content

Instantly share code, notes, and snippets.

@bi0xid
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bi0xid/93b35d2cbebceb06a2a4 to your computer and use it in GitHub Desktop.
Save bi0xid/93b35d2cbebceb06a2a4 to your computer and use it in GitHub Desktop.
WP_Query with meta query
<?php
// Ejemplo complejo. Post Type 'historia', con un campo 'fecha_de_entrega' numérico (YYYYMMDD), y otro campo 'pila'.
$args = array(
'post_type' => 'historia',
'meta_key' => 'fecha_de_entrega',
'orderby' => 'meta_value_num',
'nopaging' => 'true',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'pila',
'value' => 'sprint',
'compare' => 'IN',
)
)
);
$query = new WP_Query( $args );
// Ejemplo normal. Páginas ordenadas por menu_order y, en caso de tener el mismo, por título. Orden descendente.
$query = new WP_Query( array ( 'orderby' => 'menu_order title', 'order' => 'DESC' ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment