Recent posts headlines. How to optimize the loop

Instead of looping through each category and getting the posts for each, you can do it all in one query like this: $categories = array(‘8’, 17, 23, 423); $args = array( ‘category__in’ => $categories, ‘numberposts’ => 20 ); $recent_posts = get_posts($args); Cheers.

setup_postdata in “loop-handling” php file called via $.ajax

Solved by getting author, post_date, permalink & excerpt manually without setup_postdata: $excerpt = myCustomExcerptFunction($post, 35); $post->post_excerpt = $excerpt; // Permalinks $post->post_permalink = get_post_permalink($post->ID); // Author $authorObjekt = get_userdata($post->post_author); $post->post_author_displayname = $authorObjekt->data->display_name; $post->post_author_nicename = $authorObjekt->data->user_nicename; // Date $post->post_date_wpformat = date_i18n( get_option( ‘date_format’ ),

WordPress Tags in class

Where are you getting these tags from? Typically, to get a list of tags attached to a post, you’d do: $some_tags = wp_get_post_tags( $post_id); and then itterate through as such: foreach($some_tags as $tag) { do stuff }

Display single post inside accordion based on form submission results

Closing off as the issue is resolved. For anyone interested, the result is as follows (refer to the code detailed above for the initial DB-table connections, as the code below refers to the output only): if (isset($SelectedLocationID) && isset($SelectedSchoolID)) { ?> <div id=”resultsDiv”> <div id=”resultsHead”> <h3>Search results for routes between:</h3> <b><?php echo $selectedLocationName; ?></b> and … Read more

How to fix pagination for custom loops?

The Problem By default, in any given context, WordPress uses the main query to determine pagination. The main query object is stored in the $wp_query global, which is also used to output the main query loop: if ( have_posts() ) : while ( have_posts() ) : the_post(); When you use a custom query, you create … Read more

Why my title change the last post title in my loop?

To start this off, you should not be using query_posts for custom queries. Directly from the codex Note: This function isn’t meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of … Read more

Featured posts and the loop

A simple approach could be to use a global array in which you will store posts that are selected in the featured query. You could set this array in your functions.php or index.php : $featured_post_array = array(); Then in your featured.php file first call the global array somewhere in the beginning: global $featured_post_array; and inside … Read more

Loop in taxonomy for terms and post

There are a few things wrong: In your code you are using the same $args array in the WP_Query call that you used in your get_terms call. Perhaps you meant to use $postargs in the WP_Query call? @Milo is correct…you should be using posts_per_page, not number. Your tax_query array element ‘field’ says ‘name’ but you … Read more

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