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 would I get 1 latest post from a query for 5 posts?

You can use $current_post property of WP_Query $query_args = array( “posts_per_page” => “5” ); $listedPosts = new WP_Query($query_args); // the loop if ( $listedPosts->have_posts() ) { while ( $listedPosts->have_posts() ) { $listedPosts->the_post(); if ( (int) $listedPosts->current_post === 0 ) { // loop content for hero post } else { // loop content for remaining posts … Read more

Sorting posts according to view counts not working

Your code doesn’t make sense. You use query_posts(), which you should never do, but all that does is clobber the main query. You don’t use the clobbered query though. You then use get_posts() with an undefined (so far as code posted indicates) argument list, so it is not going to return what you expect. I … Read more

Remove arrows from previous and next link

You should have to look at what the codex says about previous_post_link( $format, $link, $in_same_term = false, $excluded_terms=””, $taxonomy = ‘category’ ) and next_post_link( $format, $link, $in_same_term = false, $excluded_terms=””, $taxonomy = ‘category’ ) Both have the same parameters, the first parameter $format is the important one to have a look at here Format string … Read more

How to make post sticky in the admin page?

“Admin Stickies” for custom post types: To support sticky custom posts in the backend, you can use the following code snippet in your functions.php file in the current theme directory or in your custom plugin: /** * Set admin stickies for the ‘foodmenu’ custom post type */ add_action( ‘init’, function() { if( function_exists( ‘wpse_cpt_stickies’ ) … Read more

Remove Shortcode […] from Blog Preview

You can do with PHP. Just remove part where is get_content() and add this: <?php $content=get_the_content(); $content = preg_replace(‘#\[[^\]]+\]#’, ”,$content); echo apply_filters(‘the_content’, $content); ?> That is regular expression added inside content. This regex will remove all tags inside content.

Sorting posts according to the term they belong to

I’m not going to discuss implementation of a slider, that is too broad. There are a couple of tutorials around which you can look at on how to implement simple sliders The real issue here is the query itself. Sorting a query by the terms a post belongs to is quite heavy operations, and if … Read more

wp_insert_post works, but the post isn’t visible in the admin post list or front end

The problem is $postarr[“post_status”] = “published”; you should change it to $postarr[“post_status”] = “publish”; // Set it to ‘publish’, not ‘published’ Now, this is a bit off topic, but you may want to omit the following (those are created by the wp_insert_post() by default): $postarr[“post_date_gmt”] = date(‘Y-m-d H:i:s’, time()); $postarr[“post_date”] = date(‘Y-m-d H:i:s’, time()); $postarr[“post_modified”] … Read more

Easy way to delete 70k posts and attached media?

If you know how to find the posts, then we can use WP CLI to do a 2 step process. First, grab all the post IDs in those categories using wp post list E.g. posts=$(wp post list –field=”ID” –category__in=”1,2,etc”) wp post delete $posts –force Then we can plug the values in posts into wp post … Read more

Bulk Image Uploader to create new post from each image [closed]

add_action(‘add_attachment’, ‘create_post’); function create_post( $attach_ID ) { $attachment = get_post( $attach_ID ); $my_post_data = array( ‘post_title’ => $attachment->post_title, ‘post_type’ => ‘post’, ‘post_category’ => array(‘0’), ‘post_status’ => ‘publish’ ); $post_id = wp_insert_post( $my_post_data ); // attach media to post wp_update_post( array( ‘ID’ => $attach_ID, ‘post_parent’ => $post_id, ) ); set_post_thumbnail( $post_id, $attach_ID ); return $attach_ID; }