Transient not working for custom loops

I have actually worked on a post yesterday (check it out here) and was hit by the same problem. I’m also new to the Transient API, never actually worked with it :-). The problem here is that for a specific loop you need to use a certain value outside of your transient. You are simply … Read more

Loop code is displaying pages but not actual posts

Explanation in the comments: <?php /* This is your original loop (`have_posts`). Even on a custom template, the first loop references the PAGE to which your template is– this being your homepage. In order to display posts, you must use a new query, as in the next chunk of code. */ if ( have_posts() ) … Read more

Display only text to WordPress loop without loosing the text formatting

Try this code in your theme’s functions.php file- function filtered_content($content){ $content = preg_replace(“/<img[^>]+\>/i”, “”, $content); // removes images $content = preg_replace(‘/<iframe.*?>/’, “”, $content); // removes iframes return $content; } add_filter(‘the_content’, ‘filtered_content’); This will remove img and iframe tag from your content. Then use the_content() in your template.

What exactly defines a Main Loop and a Secondary Loop?

When you visit a link of your site, WordPress recognizes that link and understands (using the rewrite rules you have defined or using the query vars in the URL if there are no pretty permalinks) what is the request of the URL. After that WordPress, using this request, run a query. This is the main … Read more

Remove child products from woocommerce category page [closed]

you want to display only parent category products and remove the child category products. Add the following lines of code at the end of your theme’s functions.php file. function exclude_product_cat_children( $wp_query ) { if ( isset( $wp_query->query_vars[‘product_cat’] ) && $wp_query->is_main_query() ) { $wp_query->set( ‘tax_query’, array( array ( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => … Read more

How to solve suspected memory issue in custom WordPress loop?

There are approx. 10,000 items returned by the query. That’s your problem right there. No matter what you do inside the loop, WordPress is still loading 10,000 post objects into memory. Batch it up and sprinkle a little magic in your query arguments: $args = array( ‘fields’ => ‘ids’, // MAGIC! Just get an array … Read more

Use the_content outside the loop

If you are trying to do it for the current page you are on you can just use this: global $post; $content = $post->post_content;` This will get the content for the current post instead of having to set the ID specifically.

Broken pagination

I see a few issues that are probably contributing to your issue: Only ever use query_posts() to modify the primary Loop. The caller_get_posts parameter has been deprecated, in favor of ignore_sticky_posts The $wp_query variable is a defined global. Using it outside of its intended use may cause unintended circumstances. So, first, you need to determine … Read more

Find most recent authors

Use a custom SQL query to grab the latest 16 post IDs with unique authors; $post_IDs = $wpdb->get_col( “SELECT ID FROM $wpdb->posts WHERE post_type=”product” AND post_status=”publish” GROUP BY post_author ORDER BY post_date DESC LIMIT 16″ ); Then start up a new query with the post__in argument; $recent_posts = new WP_Query( array( ‘post__in’ => $post_IDs, ‘post_type’ … Read more