file_get_contents returning different in filters and actions

If I understand you correctly, your dummy_data.json file is placed in the root directory of your page (the same directory where index.php and wp-config.php are placed), right? In that case you can easily access that file passing this path: ‘dummy_data.json’ only when your code is run from index.php file. But AJAX calls are fun from … Read more

Merge wp_get_post_terms

Rather than placing the result of wp_get_post_terms() into $episodes[$i], you can just merge it into the $episodes array using array_merge(), like this: $episodes = []; // Initialise as an empty array first. while( $animes->have_posts() ) { $animes->the_post(); $animeID[] = get_the_ID(); $args = array( ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’, ‘fields’ => ‘all’, ‘meta_query’ => [ … Read more

Allow specific user to edit a specific page

The issue is that an empty return value from map_meta_cap will grant all users permission to do that thing, because that’s essentially the same thing as saying “no capabilities are required to do this”. What you really want to do is just add edit_special_page to the existing list of required capabilities: add_filter( ‘map_meta_cap’, function( $caps, … Read more

Latest posts feed with a specific post always first

Since you’re using get_posts() rather than WP_Query, it’s sufficient to retrieve the specific post separately with get_post(), and then add it to the beginning of the results array with array_unshift(): $postslist = get_posts( $args ); $featured_post = get_post( 123 ); array_unshift( $postslist, $featured_post ); foreach ( $postslist as $post ) : setup_postdata($post);