How to return loop contents

There are replacements that return pure strings for all parts, no need to print anything into an output buffer. I like sprintf() and would write your example like this: <?php if ( $cms_pl_pages->have_posts() ) { $content=”<section class=”cms-pl-gallery”>”; while ( $cms_pl_pages->have_posts() ) { $cms_pl_pages->the_post(); $content .= sprintf( ‘<article class=”cms-pl-item clearfix”> %1$s <h2> <a href=”https://wordpress.stackexchange.com/questions/57000/%2$s” title=”Read %3$s”>%4$s</a> … Read more

Why do themes rely on “The Loop”?

You are thinking of WordPress templates as PHP application code. Essentially they are not that. WordPress templates by design are templates using Template Tags API. It is extra level of abstraction, that just happens to allow to use rest of PHP language too. The ease of template tags serves the popularity of WordPress and extremely … Read more

A search for ‘0’ returns results

Considering @Mayeenul Islam comment: I’ve just tested in a blank theme with dummy data, search with 0 (zero) fired an empty search – that means all: SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type IN (‘post’, ‘page’, ‘attachment’) AND (wp_posts.post_status=”publish”) ORDER BY wp_posts.post_date DESC LIMIT 0, 10 and the fact that wp-includes/query.php contains if … Read more

Should I use loop in the single.php file?

Stricktly speaking, you don’t need the loop in single post pages, you only need the call to the_post(). The reason for the_post() is that the_post() sets the $post global value to the single post post object

Why am I being limited to ten posts on a custom loop?

Because it must be set in back end of your wordpress site. You can check and change it from Blog pages show at most field from settings => Reading pages menu. As shown in below screenshot. It will change the setting for all pages , but if you want to make this change only for … Read more

Retrieve each widget separately from a sidebar

I am taking the core of the question to be: “… I’m not able to retrieve the widget class name” You will need to check the global variable $wp_registered_widgets to fill in the missing information. This proof-of-concept code should give you the idea. The code assumes a sidebar named sidebar-1. You will have to adjust … Read more

How to force excerpts / teasers in the loop

EDIT OK, there is a very hidden native function, get_extended() that I never knew about and greatly explained by @kaiser in his answer. My answer should only be an extension to the answer by @kaiser ORIGINAL ANSWER There is no native function to do this. The best here would be to use a PHP function … Read more

remove tags from the_content

By default, WordPress adds paragraph tags to category descriptions. Stop this by adding the following to your functions.php file // Remove p tags from category description remove_filter(‘term_description’,’wpautop’); Simple and easy (codeless). Thank you

Remove the Homepage Query

The posts_request filter Skimming through the WP_Query we find this part of interest: if ( !$q[‘suppress_filters’] ) { /** * Filter the completed SQL query before sending. * * @since 2.0.0 * * @param array $request The complete SQL query. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $this->request = apply_filters_ref_array( ‘posts_request’, … Read more

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