Using get_the_excerpt() Before The Loop

So you are basically also looking for a fallback in case your excerpt is empty? I suppose this question/answer could be helpful for you: “get_the_excerpt() with fallback like the_excerpt()“. It describes, how to build your own “excerpt” in case there is none – like this: $excerpt = get_the_content(); $excerpt = esc_attr( strip_tags( stripslashes( $excerpt ) ) … Read more

Prevent Headers from being sent

“Headers already sent” is not a WordPress error, it is PHP processing error message. Good explanation here; https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php . I suspect it might be caused by some characters (probably space characters) sent before your <?php code segment. Even space (or tab [code formatting] ) characters will cause an error. And perhaps move your <ul> code … Read more

A loop with all articles with certain text strings in tags

Based on @birgire’s always-useful comments, I did write a workaround for you. What I’m doing is to first find the terms that match the search string. Then, based on the found terms I will do a query in those. function wpse_posts_by_tagname( $string ) { // Let’s find every tag that has ‘coffee’ in it’s name … Read more

Loop first six posts in carousel, next eight in grid

Use WP_Query with offset like this <?php $offset = 6; $post_args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => $offset, ); $slider_blog_posts = new WP_Query( $post_args ); ?> <?php if ( $slider_blog_posts->have_posts() ): ?> <div class=”carousel”> <?php while( $slider_blog_posts->have_posts() ): $slider_blog_posts->the_post(); ?> <?php get_carousel_slide( get_the_ID, true); ?> <?php endwhile; ?> </div> <?php endif; ?> <?php wp_reset_postdata(); … Read more

Meta Query with spaces in value?

Try to pass your multi value in array, example ‘meta_query’ => array( array( ‘key’ => ‘some_key’, ‘value’ => array( “value1 with space”, “value2”, “value3”, ), ‘compare’ => ‘IN’ )

How to get an array of years from all of the search results, and use it to filter by year the paginated loop?

This is really interesting one! I’ve tried to solve this, and here is what I ended up with. With a pure SQL, we have an ability to get all distinct years of all our posts with the following SQL request (recipe founded here): SELECT DISTINCT YEAR(wp_posts.post_date) FROM wp_posts getting something like this: mysql> SELECT DISTINCT … Read more

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