Loop with break in the middle

Try using a loopcounter based on the post number count – provides for more flexibility <?php if (have_posts()) : ?> <?php $count = 0; ?> <?php while (have_posts()) : the_post(); ?> <?php $count++; ?> // if you are in your first post <?php if ($count == 1) : ?> // do whatever you want to … Read more

WordPress search exact match

You might want to append the query parameter sentence=1 in your search, it is not well documented, but it should retrieve content inside the post that matches exactly the sentence pattern. Alternatively, for a more powerful search, you might want to give a look at Relevanssi plugin. A lot of people agree that WordPress search … Read more

Loop inside the loop

I would use get_posts() for your two ad hoc Loops. (Actually, you only need one ad hoc Loop, if you’re modifying the main Loop so that only 2 posts are retrieved.) e.g. \\ code modify main Loop to return only 2 posts goes here $firstpost = true; if ( have_posts() ) : while ( have_posts() … Read more

How to get post meta value and post in one query?

When you do a query WordPress already gets the post_meta. Even though you are calling get_post_meta() It is not performing another query. It is retrieving the value from the post meta cache. Now if you don’t need the post meta you can set a flag that will eliminate the additional MySql query. To do this … Read more

tax_query in WP_Query problem

Thanks to Rarst for pointing me in the right direction. After a bit of playing around the following query is now producing the effect I’m after: $query_args = array( ‘numberposts’ => $limit, ‘order’ => ‘DESC’, ‘orderby’ => ‘post_date’, ‘post_type’ => ‘match’, ); $query_args[‘meta_query’] = array( ‘key’ => ‘played’, ‘value’ => true, ); if ( isset( … Read more

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