← WordPress

Ordenar resultados da pesquisa

Lida 4632 vezes

Offline

Thomato 
Membro
Mensagens 4125 Gostos 3
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

Dá para ordenar os resultados da pesquisa?

Inventei um bocado e com isto
Código: [Seleccione]
<?php {
query_posts($query_string '&orderby=title&order=asc');
}
?>
que uso para listar as categorias, tentei isto:

Código: [Seleccione]
<?php if ( have_posts($query_string '&orderby=title&order=asc') ) : ?>

Mas não deu. No meio da pesquisa encontrei uns plugins, mas não estou muito para ai virado.

Alguma solução? :)
Offline

Thomato 
Membro
Mensagens 4125 Gostos 3
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

:cool:
Offline

Luís Marquês 
Membro
Mensagens 1430 Gostos 19
Feedback +27

Troféus totais: 24
Trófeus: (Ver todos)
Apple User Windows User Super Combination Combination Topic Starter Poll Voter Level 4 Level 3 Level 2 Level 1

Já tentaste colocar o 'order by title asc' na $query_string ?
Offline

Thomato 
Membro
Mensagens 4125 Gostos 3
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

Já tentaste colocar o 'order by title asc' na $query_string ?
Se percebi o que querias dizer, acho que fiz isso no segundo exemplo que dei :)
Offline

Thomato 
Membro
Mensagens 4125 Gostos 3
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

É relativamente urgente. Se alguém souber, obrigado :)
Offline

rtbfreitas 
Equipa
Mensagens 1497 Gostos 9
Feedback +24

Troféus totais: 30
Trófeus: (Ver todos)
Windows User Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4

Queres aplicar isso a todas as pesquisas certo?

Se sim, experimenta o seguinte, no search.php:

Código: [Seleccione]
<?php if (have_posts()) : ?>

<?php $search_order = new WP_Query();
$search_order->query('orderby=title&order=ASC');
while ($search_order->have_posts()) : $search_order->the_post();?>


// conteudo

<?php endwhile; ?>


<?php else : ?>

                 // sem resultados

<?php endif; ?>

Depois diz se funcionou ;)
Offline

Thomato 
Membro
Mensagens 4125 Gostos 3
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

Está a mostrar-me sempre os mesmos resultados, independentemente da key e da página :-?
Offline

rtbfreitas 
Equipa
Mensagens 1497 Gostos 9
Feedback +24

Troféus totais: 30
Trófeus: (Ver todos)
Windows User Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4

Não cheguei a testar, vou ver se faço uns testes, se conseguir coloco aqui o código ;)
Offline

Thomato 
Membro
Mensagens 4125 Gostos 3
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

Não cheguei a testar, vou ver se faço uns testes, se conseguir coloco aqui o código ;)
Muito obrigado mesmo :)
Offline

rtbfreitas 
Equipa
Mensagens 1497 Gostos 9
Feedback +24

Troféus totais: 30
Trófeus: (Ver todos)
Windows User Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4

Muito obrigado mesmo :)

Vamos lá ver se é desta :) , eu testei e pareceu-me estar a funcionar como queres, no search.php:

Código: [Seleccione]
<?php global $wp_query;
$args array_merge$wp_query->query, array( 'post_type' => 'post''orderby' => 'title''order' => 'ASC' ) );
query_posts$args ); ?>


<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

       // conteudo

<?php endwhile; ?>

              // navigation

<?php else : ?>

              // sem resultados

<?php endif; ?>

Nota: ali o post_type serve para filtrar, assim só mostra resultados dos posts, se quiseres mostrar tudo é só apagares essa parte.

Testa e diz se era isso.
Offline

Thomato 
Membro
Mensagens 4125 Gostos 3
Feedback +2

Troféus totais: 28
Trófeus: (Ver todos)
Apple User Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2

Obrigado :)
Funciona como quero. Está com um problema estúpido que eu vou tentar resolver. Se precisar, já digo alguma coisa :)