WordPress function to get term or post object by id

get_queried_object() will get the currently queried ‘thing’ from the main query as an object. That could be a WP_Post, WP_Term, or WP_Post_Type (for post type archives) object, but I don’t think that’s quite what you’re asking for and wouldn’t be useful in AJAX. Other than that there isn’t a function for exactly what you’re asking … Read more

How do I set the url to make an ajax request for a html document?

Yes, there is such way: you should pass absolute path in there… Let’s say your JS file is enqueued like this: wp_enqueue_script( ‘my-script’, ‘path-to-js-file.js’… ); Then you should use wp_localize_script and pass the value in there: wp_localize_script( ‘my-script’, ‘MyScriptData’, array( ‘ajax_url’ => site_url(‘/test/file.html’) ) ); Then you can access this value in your JS file … Read more

Can part of my WordPress website be headless?

You can mount a react or a vue app partially into a page, so what you ask is theoretically possible but probably not the best solution. You may consider expanding the react application a bit and go fully headless. In this case, next.js (based on react) might be a better solution as it will allow … Read more

is_home doesn’t affect content

You need to is is_front_page() instead of is_home(). is_home() actually refers to the blog page (or the home page if you have it set to show latest posts). is_front_page() refers to the page (regardless of whether it is a static page or a latest posts feed) that sits on the front of your site.

Check if username exist with AJAX

The problem is with your jQuery selector: var usr = $(“#site-addres-input”).attr(‘value’); Will get the default value of the input element. Typically this will be blank, because you’re not setting it ahead of time. You need to use: var usr = $(“#site-addres-input”).val(); I’m also noticing that you’re using #site-addres-input, but “address” has two s at the … Read more

update_user_meta doesn’t work with AJAX

First You can get rid of nasty globals in your AJAX call. I’m not sure what the $st variable that you were output is all about so I’ve excluded, but you can include as you wish – add_action(‘wp_ajax_change_subscription’, ‘change_subscription’); function change_subscription(){ if(!empty($_POST[‘term_id’]) && !empty($_POST[‘type’])) : $user_id = get_current_user_id(); update_user_meta( $user_id, ‘hannit_meta’, ‘My Value’ ); endif; … Read more

query vars in url work but not in ajax call

That’s not the right way to specify data. When you’re using jQuery AJAX, you specify data as an array or an object when passing it in to the method. In your question, it seems like ‘filters_get’ === ‘?actor=x&’ Instead, you should do the following: filters_get = { ‘actor’: ‘x’ }; $.ajax({ url: templatePath + “getmovies.php”, … Read more