How to create shortcode to display custom field value on a custom post type

You’ll have to use add_shortcode to achieve this. Let’s say that you want this shortcode to be called “my_cf”: function my_cf_shortcode_callback( $atts ) { $atts = shortcode_atts( array( ‘post_id’ => get_the_ID(), ), $atts, ‘my_cf’ ); return get_post_meta( $atts[‘post_id’], <FIELD_NAME>, true ); } add_shortcode( ‘my_cf’, ‘my_cf_shortcode_callback’ ); Now you can use it by putting [my_cf] or … Read more

Custom meta box not saving

Well, there’s a lot of code you’ve posted and the reason for the problem is pretty easy to fix (but hard to find). You have this line in your code: add_action(‘save-post’,’ktechs_save_contact_email_data’); But there is no hook called save-post. It should be save_post. So change the line above to add_action(‘save_post’, ‘ktechs_save_contact_email_data’ ); and it should work … Read more

How to only show posts assigned to current user, only in certain post types

Roles and capabilities are used to control access and normally you should use them. For example, capabilities edit_other_posts and edit_published_posts are needed to edit other user’s posts. It’s the same with othe types (pages -> edit_other_pages, edit_published_pages). Since, besides limiting the right to change other user’s posts, you also want them to be invisible, you … Read more

Include only recents custom posts in WP rss feed

Removing lastBuildDate: lastBuildDate should not be removed from the rss feed, it may cause rss feed validation error/warning. However, it’s possible to filter the date using get_lastpostmodified filter hook. Filtering feed content listing: The rules for filtering feed content listing is the same as the rules for filtering any content listing in WordPress, the only … Read more

how to get URL of media uploaded to WordPress via media_handle_sideload()

To get the URL of the uploaded image/attachment, you can use wp_get_attachment_url() (which always returns the full-sized image URL) or wp_get_attachment_image_url() for image attachment: // This is how you should call uploadImageToMediaLibrary(); assign the value to $att_id. $att_id = uploadImageToMediaLibrary($post->ID, $external_url, “custom_alt”); $url = wp_get_attachment_image_url( $att_id, ‘full’ ); // full-sized URL But to set the … Read more