Eliminate duplicates in a foreach loop [closed]

Use array_unique() <?php foreach($users as $user) { $states[] = get_cimyFieldValue($user->ID, ‘STATE’); // Grabing their state from their profile page } $states = array_unique($states); ?> <div class=”state”> <input type=”hidden” name=”search_type” value=”members”> <select id=”stateDrop” name=”state”> <option value=”name”>State</option> <?php foreach($states as $state) { echo ‘<option value=”‘.$state.'”>’.$state.'</option>’; } ?> </select> </div>

How to defeat “Blog pages show at most __ posts” setting in the loop?

Instead of using the default loop, perhaps try building your own query. Basically, it’ll look something like this: $your_posts = get_posts(‘cat=123&posts_per_page=123’); foreach ($your_post as $post) { do_something-with($post); } You can display all posts by either use the param ‘posts_per_page’=>-1 or nopaging=true. (Not sure why someone voted this down? IMHO said person should comment on how … Read more

Show only posts from todays date [duplicate]

If you just want posts from today, it’s super easy and right in the WP codex: <?php $today = getdate(); $args = array( ‘date_query’ => array( array( ‘year’ => $today[‘year’], ‘month’ => $today[‘mon’], ‘day’ => $today[‘mday’], ), ), ); $custom_query = new WP_Query( $args ); ?> <?php if ($custom_query->have_posts()) : while ($custom_query->have_posts()) : $custom_query->the_post(); ?> … Read more

How do I show the post title if an advanced custom field hasn’t been used?

If in doubt, check the documentation first: https://www.advancedcustomfields.com/resources/get_field/ Check if value exists This example shows how to check if a value exists for a field. $value = get_field( ‘text_field’ ); if ( $value ) { echo $value; } else { echo ’empty’; } So, in for your case you would need to use: <?php $short_testimonial … Read more

How wp maps urls into files

Go to “Pages” and find the page with the ID. Open it in editor. On the right hand side, look for “page attributes”. You can add php files here. All you have to do is, create a PHP page under your theme, and add this to your beginning of the file: <?php /* Template Name: … Read more

WooCommerce custom loop pagination on front page

Can you please try below code? $paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : 1; $woo_home_query = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => $top_selling_products_nr, ‘meta_key’ => ‘total_sales’, ‘paged’ => $paged, ‘orderby’ => ‘meta_value_num’ ); <?php if ( $woo_home_query->have_posts() ) : ?> <div class=”products container grid-wrapper clear”> <div class=”row”> <?php while ( … Read more

have_posts() return false on single post

Late answer but, one possible scenario this could be happening is if you register two custom post types with the same permalink slug. You can debug this by doing a var_dump of the global variable $wp_query. global $wp_query; var_dump($wp_query); Check to see if the post_type in the query matches the post type of the page … Read more

‘posts_per_page’ => ’10’ does not show any post

after days of research, I found that the fault was simply in the pagination. By changing the pagination code, I have made it work. <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $custom_args = array( ‘post_type’ => ‘veranstaltungen’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘paged’ => $paged, ‘posts_per_page’ => ’10’ ); $wp_query = new WP_Query($custom_args); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)