The $post
in your callback handler is an object, and object properties, like variables, are case sensitive. So you have to use $post->ID
, not $post->id
.
The question here is: How can we prevent errors like this one during development?
For objects, there is a simple solution: use type hinting and an IDE that makes use of it.
If you change the signature of your callback handler to this …
function eli_changeProductLink($permalink, \WP_Post $post)
… an IDE like PHPStorm or Eclipse will suggest the correct property names while you are typing:
The second lesson we can take from this: Use a consistent naming scheme for your own variables and properties, unlike WordPress which is mixing uppercase and lowercase, underscore and hyphens in names. Sticking to just one scheme will make the life of others easier when they have to work with your code.
Related Posts:
- Attach a Custom Post Type to a Woocommerc product as a variation or add-on [closed]
- Exclude a term of a taxonomy with a custom post type in a search
- How to solve suspected memory issue in custom WordPress loop?
- Query for posts from any post type but only add instock products
- WooCommerce – Show orders for a specific product ? [closed]
- Set meta_query only for specific post type
- get_terms won’t display product_cat or any other custom taxonomies when specified
- Woocommerce query specific product from specific category
- Problem adding column to WC Subscription [closed]
- Create custom post type on successful woocommerce order [closed]
- how to get URL of media uploaded to WordPress via media_handle_sideload()
- How to display product subcategories into my custom post type single page
- Get post from custom post type order by two taxonomies
- changing meta value and meta key of price field
- Woocommerce search pagination not working
- WooCommerce Customer Role Delete Custom Post Type
- WooCommerce sort products by the actual product width(not the shipping width)
- Manage custom post type in woocommerce /my-account/ page
- Woocommerce custom field search in custom post type [closed]
- Modifying custom post type created by WooCommerce
- Hide a widget inside a div on specific type of post
- Allow add new post access to custom post but not wp post for some role
- How to Get WordPress custom post data in WooCommerce product meta panel? [closed]
- Display Woocommerce Orders for specific author [closed]
- Sort posts in loop by the WooCommerce Membership of the author
- How to set up Custom Post Type archive page as Front page
- Copy order items with metadata between orders – Woocommerce
- Update Post Status On Woocommerce Payment Complete
- Get all post from a post type
- Custom Post Type to replace Woocommerce products – page not found error
- CPT as Product in WooCommerce
- Blank search results on custom search
- Get Terms from Custom Taxonomy and Current Post
- Is it a connection or relationship between 2 custom post types?
- Custom Post type to Woocommerce Product type
- How to display related posts using the same taxonomy for custom types (WordPress, Pods, Woo)
- How to display custom field in product description?
- Add two custom product type
- Duplicate the “Orders” list on Admin Page
- What’s the best way to do this: inquiry/ticket system?
- Sudden 404 pages on product category archives
- WordPress shortcode to pull product post data
- ‘Simple’ Reservation System
- Change display of product price on product show page only
- edit.php all post not working
- How to show link to product in custom fields?
- add action save post type and update post meta woocommerce
- WooCommerce – Custom related product (Spareparts)
- Convert attribute woocommerce terms (taxonomy terms) in posts of custom post type
- WooCommerce change
- WooThemes – Vendors / Bookings – Allow Vendors to manage resources
- Search in multiple specific post types
- woocommerce post_type conflict with existing post type
- Custom Taxonomy not working front side Woocommerce
- WooCommerce breadcrumb display custom posts instead of product data
- Custom Taxonomy is disabled on Edit page
- CPT or Custom Table for Repository of Serial Numbers
- Get Non-Paginated Index of Post in Paginated Query
- Complex strcuture as CPT or taxonomy for use in woocommerce product variations [closed]
- Custom Search Template for Custom Post Types
- WP_Query wooCommerce category
- WooCommerce – Complete Order when an action occurs
- How to manage a bookstore
- Issue On Listing Woocommerce Parent Tag List
- Create a WordPress Database query to find users who purchased specific product through WooCommerce [closed]
- Pre defined checkbox / radio button state based on value stored in ACF fields in checkout form WooCommerce
- I am having a problem with fetching product data in the Gutenberg block editor
- How to have this permalink structure: post_type/postname/custom_inner_page
- A case for Hierarchical Custom Posts
- Disable user from updating certain posts
- Custom title set on quick edit
- Suggested Post and Taxonomy structure
- Problem: wp_query outputs all images on site
- pre_get_posts for custom page builder meta box
- How do I require the specification of term in a custom post type and custom taxonomy?
- Additional section in custom post type permalink
- Disable closing on metaboxes
- Pre-styling post content to display in lightbox
- Custom archive page for CPT UI
- Static page determines as home, but it is not
- Custom Post, set object Taxonomy terms in plugin
- Edit the author of custom post type
- CPT Template Not Showing – Getting 404
- Query Custom Post Type Taxonomy term with multiple parameters
- I am having Trouble to get list of Categories of Custom post Type
- How to Create a WordPress Plugin With Custom Post Type/Custom Field Features?
- Display post content with respect to its title?
- Hierarchy and access control for Custom Post Types (CPT)
- Changing default ‘posts’ parameters with register_post_type_args
- Multiple (two) category postings on the same page.
- Admin Column does not populate with data
- Update database from Quick Edit according to Checkbox state of Custom Post Type
- Custom fields (wp_post_meta) vs Custom Table for large amount of data
- “Submit for review” for updates on existing posts
- Access to CPT but not to ‘post’ post type
- Auto Complete Search
- Custom Post Type slug same as page name
- How to query WordPress posts bycustom field with a max characters’ length
- Page builder plugins Vs advanced custom field and Custom Post type [closed]
- manage_edit-{post_type}_sortable_columns sorts, but wrong!