Developing a “fallback” for empty wp_query results based on post dates

PHP strtotime() takes some weird string values that we can use in combination with the WP_Query date_query ‘before’ keyword. For example, we can get X posts before 1 year before tomorrow: $tomorrow_a_year_ago = wp_date( ‘Y-m-d’, strtotime( ‘-1 year +1 day’ ) ); $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 5, ‘post_status’ => ‘publish’, ‘orderby’ … Read more

Is it possible to automatically set the publication time to 8am on new posts?

you can automate this hour selection with the following code. take into account that this code also affect the date of a post created trough the API. add_filter(“wp_insert_post_data”, function ($data, $postarr, $unsanitized_postarr, $update) { if ( !$update && (“post” === $data[“post_type”]) && (“auto-draft” === $data[“post_status”]) ) { $date = current_datetime() ->modify(“tomorrow 08:00:00”) ->format(“Y-m-d H:i:s”) ; … Read more

Custom function wordpress php

You must be thinking something like this: In this URL: https://myawesomewebsite.com/page?custom_id=456 function check_parameter_in_url() { if ( isset( $_GET[‘custom_id’] ) { //do something } }

Function to filter numbers from string

You could use PHP’s preg_replace() to wrap all the numbers (ie, any successive combination of 0 through 9) in a <span> tag. add_filter( ‘the_content’, ‘wpse426625_number_wrapper’ ); /** * Wraps any number in the content in a <span> tag. * * @param string $content The post content. * @return string The content with the numbers wrapped … Read more

Add_filter just custom page types

You’re using ‘post_type’ => ‘any’ in your get_post() arguments, which will get, well, any post type. Instead, specify which post type(s) you want to retrieve. function auto_link_post_titles( $content ) { // Sets the post type(s) we’ll retrieve. $desired_post_types = array( ‘my_post_type’, ‘my_other_post_type’ ); // This is to get all published posts from all post types. … Read more

techhipbettruvabetnorabahisbahis forumueduedusedueduedusedueduseduedusedu