Put in the following line at the top of archive page :
global $post;
Thing is you need to access the global $post object before trying to use it.
Related Posts:
- How to: inspect global variables in WordPress
- get_post() vs global $post or $GLOBAL[‘post’]
- How to deal with global information without creating a Singleton class
- Using global $post v/s $GLOBALS[‘post’]
- get_query_var vs global query variables?
- What is the global $wp object used for?
- Change global values from templates
- Will $current_user no longer be global?
- How to avoid repeatedly use the new statement to instantiate a class? [closed]
- Is $page a global variable in wordpress?
- How can i use a global variable in a .css file generated with php?
- Current page id returns the incorrect value
- Echo get_the_category() outside of loop (global?)
- How does WordPress make its functions globally available?
- Recommendations on accessing current user data in WordPress
- WP user agent returns random variables
- How to get particular data from wp_list_comments outside the loop?
- How to save a viewer specific option
- What is the correct way to obtain access to the WP_oEmbed object?
- $GLOBALS[‘value1’] is not working
- Creating a (global)-mapping
- wp localize script makes variable global, how to solve that?
- using globals from wp_link_pages function
- Should we trust the post globals?
- WordPress Multisite – global categories
- How to pass arguments from add_settings_field() to the callback function?
- Passing variables from header.php to template and vice verca
- What is $post_id? is it a global variable in WordPress?
- Any advantage of using wp_scripts and is_IE when enqueuing scripts
- Global Objects and Public Methods
- Custom plugin: Trying to show saved data on frontend
- How to call a function only once (global variable scope)
- Create a global variable for use in all templates
- When and Where is `global $post` Set and Available?
- Registering AJAX callback function that is part of a class without instantiating the class in function.php
- Retrieve the template directory URI via global or get_template_directory_uri() every time?
- Filter the blog’s title without using global variables
- global $wp_meta_boxes returns NULL
- Save last login date in global before change it?
- How to check if this is the nth instance of a given shortcode in a post
- JavaScript, best way to use data from the loop
- store custom WP table names in a global variable
- Pass variables from one widget to another widget
- Using query_posts inside single.php loop
- How does the $post_type global variable work?
- How to fix a “globals” issue to avoid a rejected theme?
- Global functions on WPMU
- How/where is the global variable $wp_registered_widgets filled?
- What are the disadvantages of using global variable?
- Global $post not working in OOP function WordPress
- wp_get_current_user always returns 0 continued
- Getting $curauth->ID to work inside a shortcode
- Result of API Request to global variable?
- How to prevent XSS alter custom global javascript object & methods in WordPress
- Getting List of all registered Dashboard Widgets
- How to access plugin variables from theme templates without using globals?
- How to modify a global variable in a function and use it on another function?
- Assign External Database Queries to Global Variables and Make Them Accessible
- Best way to pass variables around a WordPress site?
- Test if php document executed by WordPress or directly
- Use a variable created in get_header to calculate stuff in wp_footer
- how to get the post id in plugin
- What does the Global Variable $s represent?
- Get current page id, title, url, etc
- What’s the safest way to switch and restore a post global?
- Why is overwriting $GLOBALS killing the_content()?
- Getting the teaser text without overriding global variables
- Is it advisable to use $post->comment_count instead of get_comments_number( $post_id )
- Retrieve post in AJAX Callback
- how to load posts to a custom post template after using template_redirect or template_include
- Php file that doesn’t recognize wordpress functions
- Understanding WordPress Search
- What’s the right way to share data between widgets?
- how do i register global query in template
- No access to global variables?
- How to show avatar of current logged in user in a widget
- Difference between $numpages & $max_page on archive pages
- How can I globally italicize list of texts in the UI database or Posts? [closed]
- The Global Styles missing
- Pass global variable from Page 1 to page 2 (Pagination)
- Global $post returns 2 objects for my shortcode
- global $product is empty string when passed into function
- Define global custom post
- External api call and make global variable for any page visitor enters , page-home, page, single etc
- Browser detection booleans mess. Caché plugin?
- How to access custom class methods from any include without using global
- Global page ID variable empty error
- I need some explanation on global $post [duplicate]
- global $post inside plugin query messes up every new post page in wp-admin
- apply_filters to $GLOBALS
- Setting a cookie in functions.php and it gets deleted when working on an other function
- Editing Global Variables from Inside Functions
- How to set global variable in functions.php
- WordPress $GLOBALS and PHP $GLOBALS
- How do I access variables outside a function [closed]
- Global Handle to Class unavailable in Plugin?
- WordPress Multisite and site speed and scaleability
- $do_not_duplicate is not working in genesis theme
- Dequeue classic-themes.min.css
- How can one use variables in a template or template part without polluting the global scope?