wp_remote_get adding backslashes

wp_remote_get() returns an array containing the response headers and the response body. When you json_encode() the response, which you appear to have done, then the body is going to be escaped so that it doesn’t break the JSON it thinks you’re trying to create. You’re adding the slashes when you do this. To get the … Read more

Get_avatar filter?

I am giving you example from storefront WordPress theme because it’s the best theme which explains everything what you want to know so here the code which is in it’s comments.php <ol class=”comment-list”> <?php wp_list_comments( array( ‘style’ => ‘ol’, ‘short_ping’ => true, ‘callback’ => ‘storefront_comment’, ) ); ?> here storefront_comment is a callback function which … Read more

Different output from WP-CLI in bash vs PHP exec()

According to Alain Schlesser in wordpress slack: The folder that the packages are installed into is set to use your server user’s home folder. When you try to execute this command from PHP, however, it is being executed by the webserver’s user, which probably has a different home folder, and the package is not installed … Read more

Remove duplicates – array_unique()

I was able to answer my question thanks to : https://wpquestions.com/Remove_duplicates_from_ACF_query/12685 <?php $posts = get_posts(array( ‘numberposts’ => -1, ‘post_type’ => ‘page’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’, )); if($posts) { /* FIRST, get all the post data */ foreach($posts as $post) { /* SECOND, one-by-one, add each data row for the specific field into an … Read more

Only show search results with if current date is between two dates?

You can use meta queries to filter posts according to your needs. Here is a sample code: function SearchFilter( $query ) { if ( !is_admin() && $query->is_search ) { $query->set( ‘post_type’, ‘visitor’ ); $query->set( ‘meta_query’, array( ‘relation’ => ‘AND’, array( ‘key’ => ‘visitor-start-date’, ‘value’ => time(), ‘compare’ => ‘<=’ ), array( ‘key’ => ‘visitor-date’, ‘value’ … Read more

WordPress custom slug (endpoint) and compare all links

All of the API functions that generate links have filters to let you alter the output. Here’s a quick example that covers most of them: function wpd_endpoint_links( $url ){ if( isset( $_COOKIE[‘lang’] ) ){ $url = $url . $_COOKIE[‘lang’] . “https://wordpress.stackexchange.com/”; } return $url; } add_filter( ‘post_link’, ‘wpd_endpoint_links’ ); add_filter( ‘page_link’, ‘wpd_endpoint_links’ ); add_filter( ‘post_type_link’, … Read more

Count top level menu items

I am not really sure whether there is some native function for this or not, but you could do it like this: $menu_object = wp_get_nav_menu_object(“Main menu”); $menu_items = wp_get_nav_menu_items($menu_object->term_id); $menu_items_count = 0; foreach ( (array) $menu_items as $key => $menu_item ) { if ($menu_item->menu_item_parent == 0 ) $menu_items_count++; }