Get recent posts with thumbnail

Actually, the condition is always returning false because you are not passing the post id to the function has_post_thumbnail() and the function always getting the default value which is null. has_post_thumbnail( $recent[“ID”] ). Same with the function get_the_post_thumbnail(). get_the_post_thumbnail( $recent[“ID”] ). $args = array( ‘numberposts’ => ‘3’ ); $recent_posts = wp_get_recent_posts($args); foreach( $recent_posts as $recent … Read more

what is the use of esc_attr() function?

esc_attr() is written specifically for escaping a string that is to be used as an html attribute, which means also escaping single and double-quote characters etc. In general, it’s better to use the data validation API that WP provides rather than the generic PHP functions.

Load post with a different template?

you can do it like this: //add my_print to query vars function add_print_query_vars($vars) { // add my_print to the valid list of variables $new_vars = array(‘my_print’); $vars = $new_vars + $vars; return $vars; } add_filter(‘query_vars’, ‘add_print_query_vars’); then add a template redirect based on that query_var: add_action(“template_redirect”, ‘my_template_redirect_2322’); // Template selection function my_template_redirect_2322() { global $wp; … Read more

delete uploaded file

Use wp_delete_attachment( $post_id ) if you have used wp_insert_attachment() before. $post_id is the attachment ID. If you haven’t used wp_insert_attachment() a simple … unlink( $upload[‘file’] ); … will do it.

Hourly Routine Not Firing ( wp_schedule_event() )

In your code example you have: wp_schedule_event( time(), ‘hourly’, ‘symbiocards_hourly_event’); but there is no symbiocards_hourly_event hook defined. If you are using it in the functions.php file in your current theme directory, then please try this snippet instead: add_action( ‘wp’, ‘symbiocards_activation’ ); add_action( ‘symbiocards_hourly_event’, ‘update_symbiocards’ ); function symbiocards_activation() { if ( !wp_next_scheduled( ‘symbiocards_hourly_event’ ) ) { … Read more

Enabling shortcodes for custom fields

Normally WordPress does not run shortcode that you put into a custom field. By default, Custom Fields display whatever value you enter, as plain-text, so if you try entering a shortcode, (in the format [shortcode] VALUE [/shortcode]) you’ll end up displaying the entire text, including the tags. Add the following in your template file, it … Read more