Get previously visited page ID

Break this down into two parts: First, we create a variable that stores that last-visited page URL, like this: $prev_url = isset($_SERVER[‘HTTP_REFERER’]) ? $_SERVER[‘HTTP_REFERER’] : ”; Then, you could either use substr and strpos to trim down everything between ?= and the / after the ID number. like this: $prev_url=”http://www.yoursite.com/?p=123″; $id_block = substr($prev_url, strpos($prev_url, “?p=”)+1); … Read more

How to obtain the user ID of the current profile being edited in WP-Admin?

There is a global variable called … $user_id available on that page. Always. From user-edit.php: $user_id = (int) $user_id; $current_user = wp_get_current_user(); if ( ! defined( ‘IS_PROFILE_PAGE’ ) ) define( ‘IS_PROFILE_PAGE’, ( $user_id == $current_user->ID ) ); if ( ! $user_id && IS_PROFILE_PAGE ) $user_id = $current_user->ID; elseif ( ! $user_id && ! IS_PROFILE_PAGE ) … Read more

get all posts ID from a category

The thing to remember about get_posts is that is uses a WP_Query object internally. get_posts source: <?php /** * Retrieve list of latest posts or posts matching criteria. * * The defaults are as follows: * ‘numberposts’ – Default is 5. Total number of posts to retrieve. * ‘offset’ – Default is 0. See {@link … Read more

Get current post id in functions.php

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. <?php add_action(‘wp_enqueue_scripts’, ‘YOUR_NAME_scripts’); function YOUR_NAME_scripts() { wp_enqueue_script(‘YOUR_NAME-js’); global $post; $params = array( ‘site_url’ => site_url(), ‘admin_ajax_url’ => … Read more

Are post ID’s reliable?

The pedantic answer is NO. While IDs are unique they can change without any change in UX as long as the change retains the consistency of the DB. And while creating a new post will generate a new unique ID, you can also create a post via code to reuse some “old” ID. In practice … Read more

Get page IDs from nav items

Menu items are stored in the posts table with a post_type of nav_menu_item. So, what you are returning is the ID of the menu item itself, not what it points to. The page/post ID that the menu item refers to is stored in the postmeta table, with a post_id that matches the menu item ID … Read more

Echo author ID in author.php

Try this code. $author = get_user_by( ‘slug’, get_query_var( ‘author_name’ ) ); echo $author->ID; Alternatively, if author name has not been set use: if ( $author_id = get_query_var( ‘author’ ) ) { $author = get_user_by( ‘id’, $author_id ); } credit @AndyAdams in the easily missed comments bellow

How do I get the current edit page ID in the admin?

You can also use $post_id = $_GET[‘post’]; Or you can use a hook (probably better). function id_WPSE_114111() { global $post; $id = $post->ID; // do something } add_action( ‘admin_notices’, ‘id_WPSE_114111’ ); You will need to add a conditional since this will run on all admin pages, I recommend using get_current_screen(); For example to run only … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)