The global $post
object represents the current post within The Loop and is created by the the_post()
function. It enables functions like the_title()
, the_content()
etc. to show the title and content for the current post without needing to pass IDs or anything.
This is why a post type archive doesn’t have a $post
object set when you’re enqueuing scripts. Why would it? What post would it represent? What would $post->post_author
be for a post type archive? It doesn’t make sense to have one because an archive is not a post.
The correct solution is the one you found: The is_post_type_archive()
function. Under the hood it checks the main Query to see if it is for the archive for a post type.
Related Posts:
- Reducing the use of global $post
- Multisite Global Custom Posts
- How does the $post_type global variable work?
- Using global $post; to get featured image for custom post via WP_Query
- How to make global post work with custom post type?
- Assign External Database Queries to Global Variables and Make Them Accessible
- Does WP have a global of $id?
- Using global $post; with custom post types
- Popup panel is only displaying 1 entry ignoring all others
- Front end post editing using a form
- Assign single template to multiple custom post types?
- Get posts based on meta key/value
- Set relationship between custom_post_types
- Search that will look in custom field, post title and post content
- Create a dropdown with Custom Post Types as option in admin
- How to list custom taxonomy categories?
- How to intercept publish post for a custom post type “event”
- clients list using wordpress
- How to add relationships between custom post types?
- Custom taxonomy query for a custom post type
- How to do a custom bookmarks post type?
- How do I add media to a custom post type?
- Custom Post Type – Archive page title
- [Plugin: Posts 2 Posts] Changing display order of connections
- How to display Custom Taxonomy of Custom post type
- Custom Post Type Meta Boxes
- Change message given when deleting post from custom post type
- associate custom post type with tags with specific pages
- how to alter args of a custom post type
- Display only custom post type count for current author on the “At a Glance” dashboard widget
- How to display recent posts added in several custom post types
- Help with CPT template pagination
- Dynamically add / duplicate custom meta in custom post types
- How to connect two custom post types with nested loops
- Comprehensively Restrict Post Type Taxonomy to Logged-in Users
- Order By Post Type ThenBy Taxonomy
- How to show CPTs in term archive
- custom post type not showing in menu
- Query/list all terms and their custom post count
- How can I make a custom post type sticky?
- Custom Post Type Dynamically Updates other Custom Post Type
- Get Taxonomy Term Title by it’s URL
- How to change wp prefix for custom post type only?
- How to handle paged param in post and custom-post-type?
- Number of Custom Post Types published are not being shown in the custom page
- Blog posts for custom post type only
- Post Type rewrite rule to point to custom Page/template
- Load Custom_post_type categories post with ajax
- sub CPT and CRUD
- Post author for revision not being set on update/insert
- Make custom post type a media library
- How to display CPT archives?
- Save and user submitted data from a form and display them in the wp backend
- current-menu-item not added on page showing custom post type (rendered with archive template)
- How to move a post to different post type with all meta data?
- Custom taxonomy or custom page templates?
- How to detect that the save_post hook is calling the callback associated to the current edit post page only
- Custom Post Type Advanced Slug
- Trying to write shortcode with get_post_meta but isn’t working
- I can’t connect my custom jquery to wp admin
- Custom post class, generate unique id from 1 to x depending on amount of posts?
- creating a foreign key like relationship with custom post types
- Include a metabox in the ‘home’ screen of a custom post type? If not, then the dashboard page?
- How to remove /blog/ prefix for custom post types in permalinks?
- Create an user checklist system for a course plateform using ACF Pro and ACF Extended
- CPT archive with WP native/core tax/categories
- Loop all post on single.php
- Create custom post type inside other post type
- How to add specific terms in a custom post type?
- How get list of job types of simple job board plugin from code?
- Changing permalink of default Post with custom post
- get_queried_object not work in taxonomy page
- Post Click Redirect to Custom URL instead of Single Post Page
- Enabling hierarchical in a Custom Post Type gives error 404
- Disable ‘Add New’ in custom post that is made from CPT UI
- custom post type to post association in wordpress
- add .html to custom post type with WPML
- Attempting to create custom “post” template, getting a 500 internal server error
- custom post type single page
- custom post type single post preview for pending status
- Custom post types not displaying per category
- Submit and edit font end custom post type
- DIVs not showing correctly on CPT?
- Create 2-layered dropdown menus for custom taxonomy and custom post type
- Updated from 3.8 to 4.2 and all post types changed to “post”
- Custom post type single display is ommited
- Fetch post meta in the same query as the main loop
- Archive.php is not displaying tags
- How to not have the items of the subtaxonomy within the parent taxonomy
- Include Custom Post Type Archive in wp_list_pages
- “regular” pages not found after changing permalink
- How to save an integer as taxonomy term?
- empty dashboard for custom role
- Get all custom_post_type posts + blog posts from one category in a single query
- How to turn custom-post archive into an overview page, listing the metadata of the posts?
- Restrict editing of a custom post type based on status and user capabilities
- How is get_the_author connected to a custom post type?
- how insert how many post type in this function?
- add_filter > posts_where works partially
- Possible to limit internal link search to post types with Gutenberg editor?