I want to place a post before all others from an ACF boleen field
-
I am currently trying to retrieve an post (to put it before all others in the search results of a search filter I created) from an ACF boolean field (and I am a beginner), so I made this script but I don’t get the expected result:
in my function.php:
// Set Meta Query Relation $metaQueryRelation = array( 'relation' => 'AND' ); // Build Meta Query Params $metaQueryParams = array( 'relation' => 'OR', 'display_not_first' => array( 'key' => 'order_by_first_post', 'compare' => 'NOT EXISTS' ), 'display_first' => array( 'key' => 'order_by_first_post', 'compare' => 'EXISTS' ), );
In the result file:
// Get WP_Query custom args. $argsRecipesGrid = buildArgs($params); $display_first = $metaQueryParams['display_first']['compare']; $result[$key] = arrayCopy( $val ); $queryRecipesGrid = new WP_Query( $argsRecipesGrid ); /** partie de code Richardson **/ $queryRecipesGrid = array(); // The sorting loop foreach ($queryRecipesGrid as $post ){ if ($display_first['compare'] == 'EXISTS'){ array_unshift($display_first, $post); } if($post->have_posts()): ?> <div class="recipes-row<?php echo $params['mines'] ? ' row-count-3' : ''; ?>"> <?php while( $queryRecipesGrid->have_posts() ): $queryRecipesGrid->the_post(); ?> <div class="recipe-col"> <a class="list--item-link" <?php if(get_post_status() == 'publish'){?>href="<?php echo get_permalink(); ?>"<?php }; ?>> <?php get_template_part('tpl/recipes/card'); ?> </a> </div> <?php endwhile; echo '</div>'; else : echo '<div class="grid-row">'; echo '<div class="grid-col-12">'; echo '<p>' . __('Aucun résultat', 'galbani') . '</p>'; echo '</div>'; echo '</div>'; endif; ?> <?php echo get_pagination($queryRecipesGrid, $params); ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘I want to place a post before all others from an ACF boleen field’ is closed to new replies.