In addition to what Tom already said, using instanceof
has worked quite well for me. (Actually never heard of is_a()
before.)
if (is_singular() && $queried_object instanceof \WP_Post) {
// do something
}
Both PHPStan and my IDE know that after this check, $queried_object
is an instance of the WP_Post
class.
Related Posts:
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- WordPress / PhpStorm / XDebug and plugin_dir_path issues
- Fatal error: Call to undefined function mysql_connect()
- How to check if feed URL was requested?
- How can I run a .php file located in my site’s root folder?
- How to return a string that has a variable inside in a shortcode?
- Cleanest/Fastest way to avoid calling and retrieving data from the database multiple times?
- Saving metabox repeatable fields
- Targeting single page with JS
- Remove General Tab and Plugin Tab in Settings in Woocommerce
- WooCommerce – Display variation custom field value [closed]
- Woocommerce HTML email option unavailable
- Use template for posts with a particular category grandparent
- How to start a script from cli within wordpress
- How to group 2 radio buttons in a widget?
- Featured image fallback link to permalink
- Changing the template hierarchy
- How to Insert Shortcodes into Theme?
- get_terms orderby numeric
- How to implement three forms(like contact form) in wordpress
- How to filter posts by post format “standard” from wp-json api?
- Register JS for block on frontend only
- Remove an action hook within a Class
- Why is file_get_contents returning page source?
- Move category description below post list in blog
- WordPress Script stops suddenly
- Woocommerce api: create product with images – bad request
- PHP Fatal error: Uncaught Error: Call to undefined function wp_kses_normalize_entities() in new wordpress installation
- Contact Fom 7 – how to add custom HTML inside span.wpcf7-form-control-wrap AND IMMEDIATELY AFTER input.wpcf7-form-control?
- WordPress admin pointers tour bug?
- Are nonces in WP REST API optional by default?
- Get term siblings of current child taxonomy
- Upload file could not be moved to wp-content/uploads
- HTML tags not showing in excerpt
- Add .htm extention to a custom taxonomy
- Pagination for custom shop loop woocommerce
- WordPress from url get external source title
- Custom gallery in wp3.5
- wp ajax return 0
- Excecuting php function in shortcode
- How to use theme function in post/page?
- Logic on a Gravity Forms redirect [closed]
- do_action(), iFrame Gets Displayed Despite Password Protection [closed]
- esc_url( ) won’t use https
- retain querystring values when savincustom options in admin
- Convert code – not work
- Use post ID in functions.php file adminside
- How to show childs of certain custom post type in option list?
- How to edit HTML of my website on WordPress? [closed]
- wpdb Cannot Update column in Database
- Change default gallery images – Currently they are displaying full size imagese
- Custom Registration username_exists / email_exists
- WordPress language switcher doesn’t work
- Custom posts password protect
- How to pick “full/thumbnail” images in the loop?
- Search.php gets metadata from first post
- WordPress Multisite login_redirect to primary blog and specific page based on role
- Pagination at category doesnt work with same name of page
- How to remove the two duplicate values
- AJAX function running TWICE with WordPress admin-ajax.php
- Is it secure to use SMTP password in .php file in WordPress website?
- Woocommerce – Exclude variation attribute on specific variation
- Sort new column in Users wp-admin
- call to undefined function mysql_connect
- Can’t pass var from php wp_ajax into ajax script : result undefined or null
- Custom PHP form needs refresh to load page correctly
- Child-Theme Category View with modified permalinks (%category% removed)
- Log out without confirmation request (nonce)
- Show data obtained from a function and place it in a shortocode function
- wp_signon works local, not on https
- Get WordPress username to customize url
- Delete empty title_tags, find a h1 heading and echo it
- Get posts from year from URL
- HELP: cannot log into wordpress. PHP error
- How to have more than one ID included in the exclude command?
- Search for images that width and height is more than 500
- How do I get object if class is instantiated only like this new classname()
- How to create a php page to collect information from a html page
- Default Image not showing up in Customizer for WP_Customize_Cropped_Image_Control
- I need help implement a Javascript code into the PHP file
- Passing different content to template parts
- My customizer’s setting doesn’t set to the default and needed to click the control’s “Default” button before it’ll be set
- Run insert if no entry otherwise run update with ajax
- Hide cart when empty [closed]
- Overwriting a Shortcode
- Post Title Not showing up
- if is_home(), change class of menu-item-225 of wp_nav_menu
- WordPress most commented posts of last X days
- How to check if a value exists in one of two database tables
- Is this WordPress code causing page weirdness? Can’t scroll to bottom
- Search result page – display values from the result’s metaboxes
- How to use multiple 404 Error Pages in WordPress
- Parse error: syntax error, unexpected ‘}’ in
- WordPress add parameters with friendly url structure
- Different behaviour between “include_once” and directly echoing out html code?
- Edit Error Page style
- How to sort wordpress posts by selecting a year from a drop down?
- WooCommerce Checkout Cart [closed]
- How can I use AJAX in child theme template?
- WordPress taxonomy and terms question