WordPress: get recent posts, delete the current category

Assuming you are using custom query to fetch the latest posts from other categories. In that case, you don’t need to hook into pre_get_posts as the category__not_in parameter can be passed directly into the query arguments. //Get the current category ID $catID = get_queried_object_id(); //Pass it to the Query arguments $args = array( //Your other … Read more

Add_action not working in required file of functions.php

Of course there can be many reasons, but if you require ajax.php in functions.php above the hook with wp_enqueue_script( ‘myJSScript’ …); – it will not work. wp_localize_script() Works only if the script has already been added. function theme_enqueue_ajax(){ //try to add wp_enqueue_script( ‘myJSScript’ …); here wp_localize_script( ‘myJSScript’, ‘ajaxUrl’, array( ‘url’ => admin_url( ‘admin-ajax.php’ ) ) … Read more

PHP 8, AJAX mail form to function.php doesn’t work

This is the cause of your problem: function true_add_ajaxform(){ … function set_html_content_type() { return ‘text/html’; } } You shouldn’t nest function definitions! Move it out of the function like this: function true_add_ajaxform(){ … } function set_html_content_type() { return ‘text/html’; }