Référence sur les fonctions et paramètres.
Nouvelle query standard :
<?php
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
// no posts found
}
Récupérer les posts : https://codex.wordpress.org/Template_Tags/get_posts
<?php
$pages = get_pages();
foreach($pages as $page)
{
if($page->post_name == 'pineau-pink')
{
echo '<div class="item" style="background: url(';
the_field('image_produits', $page->ID);
echo ') no-repeat; background-position: center 0;"></div>';
}
}
functions.php :
// -----------------------------------------------------------------------------
// Permet de tirer les posts suivant un champs personnalisé
function my_pre_get_posts( $query ) {
// do not modify queries in the admin
if( is_admin() )
{
return $query;
}
if($query->is_category('products'))
{
$query->set('orderby', 'meta_value_num');
$query->set('meta_key', 'order');
$query->set('order', 'ASC');
$query->set('posts_per_page', '-1');
}
// return
return $query;
}
add_action('pre_get_posts', 'my_pre_get_posts');
https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts