get_posts seems to be skipping the last Post

The default nmber of posts returned is 5. To return more than 5 posts use: $posts = get_posts( array(‘post_type’ => ‘events’, ‘numberposts’ => 10) ); Or for all of them: $posts = get_posts( array(‘post_type’ => ‘events’, ‘numberposts’ => -1) ); More info about get_posts http://codex.wordpress.org/Template_Tags/get_posts

Hide gravity forms

Try this; <?php $user = wp_get_current_user(); if ( count_user_posts( $user->ID ) >= 1 ) { // echo your text snippet } else { // echo your form } ?> 1) wp_get_current_user() returns the WP_User object which includes many properties for that user. 2) Since we only want the ID of the current user, we assign … Read more

How to pull a list of posts in a category while exluding posts in subcategories of the category

If you use category__in and category__not_in instead, it will only pull the posts that are in that category, not the subcategories as well. For your code, this would look something like this: $args = array( ‘category__in’ => $cat, ‘category__not_in’ => $catHidden ); Note: this will only exclude posts that are directly in the category as … Read more

get_posts() and global variables

get_posts doesn’t modify global variables & is safe to use anywhere but setup_postdata does modify the global variables. Use the function wp_reset_postdata() just after the foreach loop. It reverses the changes made by setup_postdata. The thing it does is basically same as you did in your example, you just won’t need to worry about the … Read more

How to Make infinite loop of post

A very basic example, $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1 ); $query= new WP_Query($args); while ( $query->have_posts() ) : $query->the_post(); the_content(); //example, use whatever template functions you like… endwhile; wp_reset_postdata(); //reset Post Data wp_reset_query(); //destroy query incase of using multiple queries on same page Important: Note, that this is probably an inefficient … Read more

populate array with posts

After getting the posts you can easily put them in another array & then return that array function get_sponsors() { $args = array( ‘numberposts’ => -1, ‘post_type’ => ‘movies’ ); $my_movies = get_posts($args); $options = array(); foreach($my_movies as $m) $options[$m->ID] = array( ‘label’ => $m->post_title, ‘value’ => $m->ID ); return $options; }

Why posts array is empty?

You don’t need to add the % signs to the value. WordPress does that for you automatically on a LIKE or NOT LIKE comparison. You also don’t need to “sanitize” the parameter, it will be automatically escaped for SQL. See wp-includes/meta.php, around line 806 or so.

How to retrive the text : No movie by this actor

Something along these lines should work: if ( $the_query->have_posts()){ while ( $the_query->have_posts() ) : $the_query->the_post(); echo ‘<div class=”actor-box-related”><a class=”actor-titlu” href=”‘; the_permalink(); echo ‘” title=”‘.get_the_title().'”>’; ?> <img class=”actor-img” src=”/scripts/timthumb.php?src=<?php the_field(‘img’); ?>&h=110&w=75&zc=1″ alt=”<?php the_title(); ?>” title=”<?php the_title(); ?>”/> <?php the_title(); echo ‘</a></div>’; endwhile; } else { echo(“No movie by this actor”); }

get_posts post title permalink not working for last item in array

You should use a foreach loop instead, as the count index isn’t the best way to walk over an array. <?php $speakerarray = get_post_meta($post->ID, ‘cpt_food’, true); foreach($speakerarray as $foodname) : $posts = get_posts(array(‘name’ => $foodname, ‘post_type’ => ‘food’)); $post = $posts[0]; echo ‘<a href=”‘ . get_permalink( $post->ID ) . ‘>’ . $foodname . ‘</a><br>’; endforeach; … Read more

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