How do you add Read more … link to posts?

Read more links usually appear under following conditions: Template uses the_content() function for display. Post has <–more–> tag in content, which creates teaser. Result is teaser, followed by read more link. Sometimes such links are created artificially by appending them to output of the_excerpt() function in template. So to precisely answer your question – it … Read more

How to display by default only published posts/pages in the admin area?

I’m not sure if there’s another way, but manipulating the global variable $submenu can make this work. The following is just a manual hack (I’m not aware of any hook) and may fail on non-standard submenus set ups. The regular Post post type has a unique address and the rest of types has another one, … Read more

add action only on post publish – not update

Like @milo pointed out in the comment, checking if the post meta exists is the easiest way to achieve what you want – like this: add_action(‘publish_post’, ‘wpse120996_add_custom_field_automatically’); function wpse120996_add_custom_field_automatically($post_id) { global $wpdb; $votes_count = get_post_meta($post_id, ‘votes_count’, true); if( empty( $votes_count ) && ! wp_is_post_revision( $post_id ) ) { update_post_meta($post_id, ‘votes_count’, ‘0’); } } → On … Read more

Change permalinks for posts but not for custom post types

When you register your post type, the with_front argument of rewrite should be false, so the permastruct is not appended to the front of your custom post type permalink. $args = array( // snip… ‘rewrite’ => array( ‘with_front’ => false ), // snip… ); register_post_type( ‘your-post-type’, $args );

Function to execute when a post is moved to trash .

This will do the trick! add_action(‘trash_post’,’my_trash_post_function’,1,1); function my_trash_post_function($post_id){ if(!did_action(‘trash_post’)){ // do stuff } } Here we add the function, and to prevent the hook from executing more than once using did_action: http://codex.wordpress.org/Function_Reference/did_action As always, these kinds of hooks take the form {post_status}_{post_type}, so trash_post, trash_page, trash_customposttype, publish_page etc

Possible to change the URL for the regular post type without affecting the URL of other custom post types?

You could do this on custom post type registration. 1) Set your default permalink in the WordPress admin to your desired structure e.g.: /blog/%postname% 2) Add the “slug” and “with_front” parameter to the rewrite-array in the register_post_type function. “slug” must be the name of your post-type. $args = array( // … ‘rewrite’ => array( ‘slug’ … Read more

Update post counts (published, draft, unattached) in admin interface

I got this almost working, but refinements are needed to fit the specifics of the question and to deal with Attachments and Post-Types differently (see comments in code)… First, I think it’s worth noting how I found the filter: apply_filters( ‘views_’ . $screen->id, $views ) inspect element do a global search in /wp-admin and /wp-includes … Read more

How to get post creation date?

The post_date and post_date_gmt serves as the date that the post was created. For scheduled posts this will be the date on which the post is scheduled to be published. There is no reliable native method to determine the date when a scheduled post was added. For scheduled posts, you can try the post_modified or … Read more

Get post content by ID

You can do it multiple ways. Following are best two ways. $post_id = 5// example post id $post_content = get_post($post_id); $content = $post_content->post_content; echo do_shortcode( $content );//executing shortcodes Another method $content = get_post_field(‘post_content’, $post_id); echo do_shortcode( $content );//executing shortcodes After Pieter Goosen suggestion on apply_filters. You can use apply_filters if you wanted the content to … Read more