Return Wordpress Post

Asked

Viewed 117 times

1

I have the following script that returns me the status and the amount of posts you have in this state, now I would like to display these posts, someone knows some solution?

<?php

    $query="
    SELECT 
        e.id ID,e.uf UF, e.nome Estado, COUNT( 1 ) Quantidade
    FROM 
        wp_treasuremap_posts p, wp_treasuremap_postmeta m, wp_treasuremap_localizacao_cidade c, wp_treasuremap_localizacao_estado e
    WHERE 
        p.id = m.post_id
        AND post_type =  'denuncia'
        AND meta_key =  'estado_e_cidade'
        AND post_status !=  'trash'
        AND meta_value = c.id
        AND c.estado = e.id
    GROUP BY 
        e.uf, e.nome
    ORDER BY 
        3 DESC ";

    $result=mysql_query($query);
    $tot=mysql_num_rows($result);
    $c=0;

    while($row=mysql_fetch_object($result)){

    $ID=$row->ID;

    $Estado=$row->Estado;
    $Quantidade=$row->Quantidade;
?>     
     <li>
        <a href="http://site.com.br/?page_id=22277&estado=<?=$ID;?>"><?=$Estado;?> <?=$Quantidade;?></a>
     </li>   
<?php 
  } 
?>

1 answer

3

You don’t need to use "pure" PHP within Wordpress. He has the proper functions for this kind of thing. I advise to look at the Codex. For more details on. You will need to learn about Loop of Wordpress and only Custom Post Type. You can solve this in a much simpler way. For example:

<?php $loop = new WP_Query( array( 'post_type' => 'estados', 'posts_per_page' => -1 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<a href="?php the_permalink();?>"><?php the_title();?> </a>
<?php endwhile; wp_reset_query(); ?>

"Only that" will already bring all registered states with your name for example. Wordpress is "almost a framework"...
With this you don’t need to reinvent the wheel.

  • My problem is that the data are separate tables and I need to unite all in a single selection.

  • @Henriques.Santos, right now, the problem is that your question does not have enough details... Which tables treasuremap are those? How are they created? What does that have to do with your site? Has an "edit" link just below the question, can modify the will (as long as it does not change the original meaning of the question).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.