Pages - Menu

Wednesday, 18 February 2015

Query WordPress post - Request to database

A database is convenient, even if one is able to evade the desired information. The following example can be applied to one article or Post Type personalize.

The first step is to assign the arguments, in other words; whom, in what category, how .$ Arg = ... ..

 




Creating the Loop

Close the loop

Reinstall the loop

post_type: Your guy, if you want to delete items by default.


<?php
// The Query

 $args = array(

'post_type' => 'votre_post_type',
 'posts_per_page'=> '1'
 );
 $query = new WP_Query( $args );

 // The Loop
 if ( $query->have_posts() ) {
 while ( $query->have_posts() ) {
 $query->the_post();?>

 <ul class="row">

 <?php the_title(); ?>

 <?php
 }
 } ?>

<?php wp_reset_query(); // RĂ©initialiser la requĂȘte ?>