Post Post Wordpress

1

I have the following script that returns me the status and the amount of posts it has in this state, now I would like to view these posts, does anyone know of any solutions?

<?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 
  } 
?>
    
asked by anonymous 06.10.2015 / 15:17

1 answer

4

You do not need to use "pure" PHP within WordPress. It has its own functions for this kind of thing. I would advise looking at the Codex. To have more details on. You'll need to learn about Loop from 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(); ?>

"That's it" will already bring all registered statuses with your name for example. WordPress is "almost a framework" ...
With this you do not need to reinvent the wheel.

    
08.10.2015 / 05:07