Come posso visualizzare questi post in ordine crescente?

1 gen 2013, 02:50:17
Visualizzazioni: 19.8K
Voti: -1

Sto cercando di visualizzare alcuni post in ordine crescente, partendo dal primo creato fino al post creato più recentemente. Ogni aiuto è apprezzato. Ecco il mio codice:

<?php
$numofmebers = '-1';
if ( empty($_GET['page_id_all']) ) $_GET['page_id_all'] = 1;
    $count_post = 0;
        // Query per tutti i post di tipo coach-instructor pubblicati
        query_posts( array( 'posts_per_page' => '-1', 'post_type' => 'coach-instructor' ,'post_status' => 'publish') );
        while ( have_posts()) : the_post();
            $count_post++;
        endwhile;
            if ( $node->instructor_pagination == "Single Page" ) {$node->instructor_page_num = -1;}
            // Query principale con paginazione
            query_posts( array('posts_per_page' => "$node->instructor_page_num", 'paged' => $_GET['page_id_all'], 'post_type' => 'coach-instructor' ,'post_status' => 'publish') ); 
        $counter_news = 0;
        while ( have_posts()) : the_post();
        $counter_news++;
        $image_id = get_post_thumbnail_id ( $post->ID );
        $coach_istructor_meta = get_post_meta($post->ID, "cs_coach_istructor_meta", true);
            if ( $coach_istructor_meta <> "" ) {
                $xmlObject_author = new SimpleXMLElement($coach_istructor_meta);
                    // Recupero dei metadati dell'istruttore
                    $about = $xmlObject_author->about;
                    $specialism = $xmlObject_author->specialism;
                    $qualifications = $xmlObject_author->qualifications;
                    $philosophy = $xmlObject_author->philosophy;
                    $contact = $xmlObject_author->contact;
            }
            else {
                // Valori predefiniti se non ci sono metadati
                $about = '';
                $specialism = '';
                $qualifications = '';
                $philosophy = '';
                $contact = '';
            }
?>
1
Commenti

Ascendente o discendente?

fuxia fuxia
1 gen 2013 02:52:41
Tutte le risposte alla domanda 2
1

Tieni presente che query_posts è meglio evitarlo in quanto ha effetti negativi sul loop principale. Un approccio migliore sarebbe creare una nuova istanza di WP_Query o modificare gli argomenti della query per il loop principale.

Per ottenere l'ordinamento desiderato, prova ad aggiungere quanto segue ai tuoi argomenti:

array( 'posts_per_page' => '-1', 'post_type' => 'coach-instructor' ,'post_status' => 'publish', 'orderby' => 'date', 'order' => 'ASC')
1 gen 2013 02:58:06
Commenti

Grazie per l'aiuto. Ha funzionato. Sto ancora imparando PHP e lavorando all'interno del framework Wordpress. Questo mi aiuterà anche in futuro.

Tom Geoco Tom Geoco
1 gen 2013 03:58:25
1
-2
$orde = ('orderby','date'); // Ordina per data
$ordr = ('order','DESC');  // Ordine decrescente
$query = array(
    'post_type' => array('posts_per_page'), // Tipo di post
    'orderby'   => $orde,                    // Ordina per
    'order'     => $ordr                     // Ordine
);
14 gen 2023 01:00:34
Commenti

Benvenuto su WPSE! I parametri che stai passando alla query non sono validi. orderby può essere un array, ma in quel caso la "colonna di ordinamento" (precisamente il valore che denota la colonna) deve essere una chiave nell'array, non un valore. L'uso di un array in orderby dovrebbe essere così: $args = array( "orderby" => array("date"=>"DESC") ).

nmr nmr
14 gen 2023 13:08:23