How to get current post ID in function?

How to get current post ID in function?

I want to get current post id in this function to display selected dropdown value.. Note that $post or get_queried_object_id () do not work until the first query was fired. So this options are available only at the hook template_redirect and later.

How can I get the name of a user?

It is easy to do. 1. You can get user name using HttpContext.User.Identity.Name and then load user by name, get its ID. 2. The way I’m using is to add user id as user claim while login and then get it using HttpContext.User.Claims.

How to get the current user name in homecontroller?

If you want to get the current user in other Controller like HomeController, you could use HttpContext.User, and a simple code like below: Please remember to click “Mark as Answer” the responses that resolved your issue. Hi Edward Z, thank you for your answer but I already get the Username of current_User, now I have 2 other problems:

When to hook function.php to template _ redirect?

But functions.php is included much earlier (before the hook after_setup_theme) so this isn’t a solution. Here is a overview over hook execution order. If your code is executed after the template_redirect hook these option may be better: Here is one my function what never fail.

How to get the ID of an item in WordPress?

Retrieve the ID of the current item in the WordPress Loop. (int|false) The ID of the current item in the WordPress Loop. False if $post is not set. Introduced.

Where do I find the global post variable in WP?

If you hook your localize script function to wp_enqueue_scripts, then you will have access to the global $post variable. As long as you pick a hook at or after ‘wp’ you should have access to the global $post.

How to post in the same page in simple PHP?

$getUserId = mysql_query (“SELECT id FROM `user` WHERE `userid` = ‘”.$userid.”‘”); because you are getting all the results and you need to retrive the id only and your form action should be your same page itself also check your insert query not any data values inserted.

How to PASS ID from one page to another?

I don’t think $id= $_POST [“id\\; will work since you are passing the value in the url. echo doesn’t print the variable values when using a single quoted string. there are a number of ways you could get around this issue, one would be to change those two link lines to be like this

What does the post ID look like in WordPress?

The only two permalink structures that do include WordPress post IDs are the Plain and Numeric options. Here are two quick examples of what those URL structures look like: In both cases, the post ID is 1.