//Argumentos para hacer la Query.
$args = array(
'post_type' => 'sectores',
'post_status '=> 'publish',
'posts_per_page' => -1
);
//Obtenemos las clinicas del sistema.
$sectores = new WP_Query($args);
//Si tenemos clinicas disponibles.
if ( $sectores->have_posts() )
{
//Creamos pila de clinicas.
$infoSector = array();
//Entramos en bucle para obtener las clinicas.
while ( $sectores->have_posts() ) : $sectores->the_post();
if(get_the_post_thumbnail_url()){
$location = array(
"nombre" => get_the_title(),
"slug" => get_post_field( 'post_name', get_post()),
"imagen" => get_the_post_thumbnail_url(),
"main" => get_field("main"),
"custom_link" => get_field("custom_link"),
"category" => get_the_terms( $post->ID, 'categoria_sector' ),
"descripcion" => get_field("descripcion"),
"orden" => get_field("orden")
);
} else {
$location = array(
"nombre" => get_the_title(),
"slug" => get_post_field( 'post_name', get_post()),
"imagen" => "http://www.yupcharge.com/wp-content/uploads/2018/08/sectores-yupcharge.jpg",
"main" => get_field("main"),
"custom_link" => get_field("custom_link"),
"category" => get_the_terms( $post->ID, 'categoria_sector' ),
"descripcion" => get_field("descripcion"),
"orden" => get_field("orden")
);
}
//Almacenamos las posiciones.
array_push($programasEnvio, $location);
I have this data that I take with custom fields.
$sectoresPrint = array();
foreach ($programasEnvio as $sector ) {
if($sector['category'][0]->name == "Sector principal") {
array_push($sectoresPrint, $sector);
}
}
How can I order the sectoresPrint array by the order field from lowest to highest
Taking into account that it
$sectores
is an objectWP_Query
created like this:You can make use of the parameters
orderby
andorder
that objects can receiveWP_Query
.If you modify the array that you pass as an argument indicating the order, the data will come already ordered and you will not need to undertake a new manipulation on them to do something that you can do at the moment of obtaining it.
You can then pass the arguments like this: