How to echo excerpts with wp_list_pages?

If you want to make use of all the nifty filters for the title and excerpt/content (and why would you not want that?) you should loop through a custom query instead of using get_pages and the pages’ plain contents: <?php $args = array( ‘post_type’ => ‘page’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘post_parent’ => $post->ID, … Read more

Get post excerpt and title by specific post ID?

Your get_excerpt() function uses the global $post variable, which is out of scope inside your function. // Changing excerpt length function get_excerpt($count){ $permalink = get_permalink($post->ID); $excerpt = get_the_content(); $excerpt = strip_tags($excerpt); $excerpt = substr($excerpt, 0, $count); $excerpt = substr($excerpt, 0, strripos($excerpt, ” “)); $excerpt = $excerpt.’… <a href=”‘.$permalink.'”>Read More</a>’; return $excerpt; } That means that … Read more

How to change / delete product short description in Woocommerce

Th function wp_set_object_terms() will not work to set post object properties. To add/update/delete product short description there is mainly 2 ways: 1) the WordPress way from a post ID using wp_update_post() function this way: $product_id = $post->ID; // or get_the_id() or $product->get_id() (when $product is available); // The product short description (for testing) $new_short_description = … Read more

Getting first 20 words without excerpt

Use wp_trim_words() wp_trim_words( get_the_content(), 20 ) As you’re outside the main loop wp_trim_words( $recent[ ‘post_content’ ], 20 ) If you want to apply the same filters as to the_content() in the main loop wp_trim_words( apply_filters( ‘the_content’, $recent[ ‘post_content’ ] ), 20 )

How to get the excerpt of a page before more tag?

The content is manipulated by the get_the_content function, and that function always assumes the current post in the Loop. You can’t pass it an ID, strangely. The easiest way to get just the bit before the more for an arbitrary post ID is: $p = get_post(1); $p = preg_split( ‘/<!–more(.*?)?–>/’, $p->post_content ); echo $p[0]; There … Read more

Writing a custom excerpt function

The easiest way is to use strip_tags(). // Remove all html from the excerpt. function custom_excerpt( $text ) { return strip_tags( $text ); } add_filter( ‘the_excerpt’, ‘custom_excerpt’ ); If you want to get fancy and trim the excerpt length, you can use this function. // Trim default excerpt length from 55 chars to 20. function … Read more

How to display only an excerpt of the content with custom post types?

You only need two small changes (1st and 3rd lines), though I also took the liberty of tweaking the classes on the div to what seemed more appropriate: <h1 class=”title”><a href=”https://wordpress.stackexchange.com/questions/67750/<?php the_permalink(); ?>”><?php the_title(); ?></a></h1> <div class=”excerpt event”> <?php the_excerpt(); ?> <?php wp_link_pages(array(‘before’ => ‘<div class=”page-link”>’.__(‘Pages’, ‘cpotheme’).’:’, ‘after’ => ‘</div>’)); ?> </div>