Notice: Trying to get property of non-object
Would indciate that $post
has no scope inside your function. One simple solution here would be to globalise $post
so it has scope, effectively fixing the error.
However, whenever you create a query, or run the loop and call the_post
method this gives you access to the WordPress template tags.
Rather then put in global statements you could call get_the_ID()
which should of course contain the given post’s id(ie. the current post for that iteration of the loop).
Update your problem line to read..
$custom = get_post_custom( get_the_ID() );
And that should clear up the problem, of course noting giving $post
scope inside the function would also work, it just wouldn’t look as poetic!.. 😉
Small side question back to the asker, what are you looking for when you call get_post_custom
, are you checking for some particular meta keys, or looping over every meta item you find? There may be some room for improvement there(if you’re interested).
Related Posts:
- Display all posts in a custom post type, grouped by a custom taxonomy
- Should unaltered default loop/query return a list of custom posts belonging to a custom taxonomy?
- Query for posts in 2 taxonomies
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- Why does using WP_Query inside a shortcode in an elementor page cause the arguments for WP_Query to get malformed?
- Is it possible to create a shortcode that will query a post based on taxonomies?
- wp_query to find posts by year and month
- Filter by custom taxonomy slug on a custom post type
- Display CPT posts based on specific taxonomy
- Custom loop with multiple taxonomy queries
- What’s the WP way to load remaining custom posts?
- display posts of custom post type with custom taxonomy
- List all Custom Post Type posts excluding certain Taxnomy term
- Cant’ Display Custom Post Type Title Base on Tax Terms
- Loop for custom-post-type comparing taxonomy terms for “related” posts?
- Multiple custom post type queries causing wrong post types to be grabbed in taxonomy + single templates?
- Query for specific taxonomy that executes a particular loop depending on volume of posts?
- What is the most efficient way to execute recursive complex queries?
- Get Posts List of Current Selected Custom Taxonomy in Shortcode
- Loop with Custom Post Type and Taxonomies
- Shortcode display CPT Query only showing 1 post?
- Post data in separate divs with incrementing class using WP_Query
- Catergory args causing loop not to show
- display custom post type from register taxonomy
- Complex Custom Loop with Includes
- Counting Posts of a Given Post Type Having a Specific Taxonomy?
- Displaying Posts Related to Other Posts by a Taxonomy Term?
- Querying Posts by Taxonomy From Alternate Network Site
- WP_Query on custom post type not displaying, multiple loops & get_template_part
- Conditional two level dropdown filter for custom post type
- Show all custom post type posts sorted by custom taxonomy then by another custom taxonomy
- How to create posts (not post template) to be displayed on projects page?
- WP_Query post at custom position
- 404 error PageNavi custom type taxonomy | wordpress
- IF statement in a do_shortcode
- Paginated Taxonomy Term Archive including one post per term
- How to dynamically build a multiple taxonomy query loop within a post type’s single loop?
- Get custom posts with certain ids in a custom loop using a shortcode
- get_template_part for each level of taxonomy term
- Query custom post type in the loop
- Loop through Custom Post Type, and then show children within each iteration
- Very Slow Page – How to Optimize # of Queries?
- WordPress Genesis custom taxonomy archive shows 3 repeats of each post
- Am unable to reset a query properly
- How to make sure content doesn’t display if selection is empty
- Archive for custom taxonomy lists all posts instead of current taxonomy
- Get next and previous 3 posts in a term in single post page
- Get custom post type list for every category shortcode
- Display all taxonomy terms, add class if term applies to current post
- Custom WP Query on custom meta and sort by multiple meta keys value
- WP Query with categories only shows one post and ignores the category
- Add Custom Post Type of specific Custom Taxonomy to regularly blog loop
- Only show posts with date of today or in the future (i.e don’t show past posts)?
- WP Query post__in not returning correct results
- Sort posts in loop by the WooCommerce Membership of the author
- WordPress wp_query() basic question about args
- get_post_meta is not working inside shortcode
- Custom post type, custom taxonomy, query posts only from taxonomy (children of)
- get_pagination not working on a custom post type query (using WP_Query)
- WP_Query with custom post type ID
- How to get the post terms from a child taxonomy
- Custom Post Type and Taxonomy Loop Output Is Wrong
- postsperpage value not being applied
- Exclude latest post from WP_Query taxonomy term loop
- foreach loop inside the loop creating duplicates in output
- Shortcode / WP_Query in post changes context
- How to fetch posts that are stored in the different table than (default) wp_posts?
- WP_Query order custom post type with certain meta key value by post modified date
- How do i display post from a taxonomy term?
- Display featured posts for a custom post type by taxonomy
- How to display list of custom post taxonomy terms and their posts (if any)?
- display post count in archive page that have relation with another taxonomy term
- Shortcode with loop stacks output
- How to search through all child taxonomies using WP_Query?
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- posts_per_page is not working by term
- Wrapping an unknown amount of posts inside separate HTML Containers during WP_Query loop
- % encoded URL giving 404 error in WordPress
- CPT: multiple loops with different terms
- sorting in wp query based on custom field value
- Add active class to foundation 6 tabs while looping categories
- Why get_posts() returns empty array while I am trying to get posts from some specific taxonomies and work properly with others?
- WordPress loop add heading before first of type
- Only show current category post
- Looping through custom taxonomy in one template
- get_post_meta for Custom Post Type ( CPT )
- WordPress query posts by custom post type not workng
- Get posts of an specific term of a custom taxonomy
- Checking Taxonomy Terms for a Custom Post Type With get_the_terms Not Working
- WP_Query for CPT with filter by another WP_Query
- Is it possible to add query parameters on the archive page?
- Plugin Error on activating
- How to query posts by meta keys AND under specific category?
- How can I pull information from my loop and divide them seperately?
- Storing/querying custom date data
- Fallback if statement based on the number filtered from it
- Fourth page of custom post type archive page does not exist
- Query custom post type and group by taxonomy
- Create a WordPress loop that shows posts from a custom post type + filters the posts by taxonomies while hiding empty taxonomies
- Add Custom Taxonomy Terms as CSS Classes for CPT Posts in an Elementor Loop Item Template