How to filter wp_get_recent_posts() to only posts that have thumbnails?

You can pass arguments to pass meta_query to your wp_get_recent_posts() function. wp_get_recent_posts() makes call for get_posts(), so you can make use of all the arguments get_posts() or WP_Query uses. As per your need. $args= array( ‘meta_query’ => array(array(‘key’ => ‘_thumbnail_id’)) ); $recent_posts = wp_get_recent_posts($args); Along with other arguments you want to pass to your function. … Read more

using filters on the function from class

If this is your own class that you’re doing this for, and can modify it, then you could pass the instance of the class as an addition argument to the filter callbacks: class Foo { …constructor, etc. function to_filter() { $output=”<div class=”wrap”>”; $output .= $this->another_function(); $output .= more html return apply_filters( ‘to_filter_name’, $output, $this ); … Read more

Filter on the day of the week from timestamp

This answer may help someone who really wants to customize their filters. With PhpStorm and breakpoints I could walk through how the meta_query is constructed before posts are fetched. There are no hook points in the flow that let developers accomplish this; I’ve used a SQL-injection trick to achieve the filter. // Do advanced SQL … Read more

Print url to default featured image

I would say you can’t, not possible. There is no filter for get_the_post_thumbnail_url() or get_post_thumbnail_id(). However you could apply a filter to get_metadata() which get_post_thumbnail_id() uses, and return the id of another attachment that you want to use as the default thumbnail. But I don’t recommend this it’s a bit hacky. I think you should … Read more

Set post featured image to author image

If you use the save_post hook, every time content is published or updated, the featured image will be refreshed. Note: make sure ACF is set to return an image ID, which is not its default. add_action( ‘save_post’, ‘wpse_set_featured_image’ ); function wpse_set_featured_image($post_id) { // get author id $author_id = get_the_author_id($post_id); // get author’s image $author_image_id = … Read more