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' => admin_url('admin-ajax.php'),
'post_id' => $post->ID
);
wp_localize_script( 'jquery', 'YOUR_NAME', $params );
}
Related Posts:
- Hiding posts in a list from specified categories
- Getting current post ID in functions.php
- Change post order random through out the entire WordPress
- How to do set post permalinks using 6 digit random unique function?
- Every second post different class in blog view
- How to check in functions.php if there is data in a WP_Query?
- Related Posts function not working
- WP_Query custom field pass the post id
- Query function not executed between element [closed]
- Same post appears in related Posts?
- how to show comments only author which send own posts in wordpress
- Function is printing twice – any suggestions?
- How do I apply a wordpress function to something with no ID inside an archive page?
- Show all posts from the tags without having to set all of them
- Filters do not work when there are multiple (one works)
- Search by post title and content in wp_query without order
- Hiding Draft Post In Admin
- Exclude category from
- How do I correctly set up a WP-Query to only show upcoming event-posts?
- Is it possible to change post id for an already added menu item in WordPress?
- Setting posts_per_page for taxonomy term template
- Blog post per page setting conflicting with custom WP_Query?
- How to insert 2 args into 1 Wp_Query for a slideshow
- How to exclude latest x posts from a paginated query?
- Setup a custom dynamic post
- Anyway to grab author name and featured image in an embeded in inital array of posts outside of loop?
- How to verify wp user password by sql query in wp? [closed]
- Get ALL post ID’s export list (Only id’s. Php or sql not important )
- Removing noindex posts from wp_query
- How to display the link (title) and thumbnail post?
- WP Query – Posts Per Page not working in combination with category__in
- How to get next post ID?
- Force the “Choose from the most used tags” meta box section to always be expanded
- Show the content that is after the excerpt using child theme
- Ajaxify This Code
- How to allow users to post only in certain category and hide elements from edit page?
- How to filter my search in post if contains a word in title, content or excerpt?
- How to return another post than requested
- Search results posts_orderby and ID
- Pausing and Resuming WP_Query results
- Can’t get buddypress notifications in front-end; why do I get this error?
- Select only post id and meta value with WP_Query
- Lost draft under all posts and drafts
- Get user categories with most posts in it
- How do I display some posts fully on the homepage, and some as an excerpt only?
- Random ajax load only works with posts_per_page set to -1
- How to : pagination in 3 different custom loops on the same page
- Send post id through ajax and get the post content back
- How safe is renovating $wp_query when doing WP_Query pagination in Page Template
- Exclude the first ‘n’ number of posts of a tag from home page?
- Query posts and return XML
- how to change the number of posts returned in a specific loop without making it global?
- Display post x of y within category
- Force authors to Preview a post before publishing
- WordPress Automatic Filename Changer
- Query Posts With Over 1000 Views
- posts_per_page option limits the number of Gallery items
- List authors with the last post title and order by last post date
- How to order posts by meta_value and title
- Retrieve post ID from “querying” URL
- wp_query random post
- wp_posts table: safely remove unused columns to save database storage
- Query Posts by Custom Field
- Adding a blog archive with pagination using WP_Query
- How to get Tags with specific post id
- Redirect to another page using contact form 7? [closed]
- Order posts alphabetically: how to set order=asc in mysql query?
- how can i change WP main archives loop to sort by name or title
- Using wp_list_pages() after calling query_posts()
- how to get post order by post id wp_query?
- Possible to alternate between two loops
- How to get a post’s content? [closed]
- Nested WP_Query breaking loop
- WordPress query_posts by tag doesn’t work anymore(?)
- obtain the author id given the post id
- How to get ID of the page included with get_page()?
- How to display all posts divided/ordered by post date? [closed]
- Why Query is returning empty array?
- How do I extract just the post ID of the first item in whatever WP_Query returns?
- Show post content and title in diferent divs using WP_Query using a loop
- Change all author links in Blog roll
- How to I retrieve the ID from the Posts page?
- Why are my paginated posts always returning the same results?
- Crazy Question – Updating Post ID
- Ignore latest two posts
- Is it possible to use WP_Query to only pull posts with attachments?
- disable Tab post on nav-menus page (Admin)
- Adding bootstrap classes to video shortcodes
- Why I can not I use the variable outside my function?
- Show posts by author of membership level (Paid Membership Pro)
- Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
- meta_value timestamp older than now
- Format latest/newest post differently
- Loop doesn’t exclude the specified category in home page
- is_page Funtion for Posts ?
- Get posts with multiple categories
- Do not show children of a category
- Display posts of specific category term
- Post type no single page
- Print out last 3 blogposts