You should change $parents[]
to $parents
in get_parents() function:
$parents = get_metadata('post', $post_id, WPKWP::$META_CHILD, false);
if ($parents !== FALSE && count($parents) > 0)
return $parents;
return false;
because get_metadata
return array in this case. If the $post_id
parameter is invalid, false
is returned. If the meta value isn’t set, function return an empty array.
Therefore, $parents
array always will contain one element – false, empty array or array with values. The condition count($parents) > 0
is always true.
Define variable $meta = null;
before if (WPKWP::get_parent())
. If condition is true then only local $meta
variable (invisible in return line) is created.
You define function get_parents
but in get_post_metadata()
you have WPKWP::get_parent()
.
Related Posts:
- How to make an meta_query optional?
- How to update single value in multi dimensional Post Meta?
- Modern Tribe Calendar wp-query with meta query not working at all
- Sortable admin column for one meta key with three possible meta values
- How to display custom field on homepage
- Can an array be used as a meta_query value?
- List of posts by day of the week
- WP Query with custom Shortcode
- Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
- WP_Query Check if post has one or more attached medias
- Custom query, checking values of multiple meta keys
- Archive post by meta value + 24hours
- get_users meta_query: REGEXP not working for matching new lines
- Is it possible to retrieve all posts with a certain value for metadata?
- Grouping posts by a custom meta value
- Omit custom post type from wp-sitemap.xml based on meta key using wp_sitemaps_posts_query_args
- WP_Query: getting posts where custom field exists
- User Meta Value not echoing despite Var_Dump Showing correct string
- How to hide posts of a specific custom category in WordPress?
- Passing an array into WP_Query as a variable
- WordPress meta_query >= &
- How do I remove duplicate users from two merged WP_User_Query objects?
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- How to sort WooCommerce products page by latest in-stock items first?
- Is it possible to order posts using multiple meta queries, i.e. show posts from first meta query, then the second?
- wp_Query with mutuplea values returns all posts
- meta_query search names when they have middle initials
- Usermeta data unserialize, extract and display in table in WordPress
- Meta query not showing result properly
- Filter loop by ‘price’ with meta_query
- WP_query meta_query slow with OR and DATES
- Get meta_query value by user meta array
- How to use something like meta_query but for fields?
- Efficient way of querying for a “fallback” post?
- Too many if’s and else if’s ?? – Must be better way [closed]
- get second ID from array
- How to add elements to an empty array in PHP?
- Any guides on creating custom admin pages?
- Decrease file size upload in Media
- Customize default settings on new sites on multisite
- wp_delete_auto_drafts() deletes links in menus
- WP E-commerce: Showing 3 random products from current category when viewing product
- Question about repurposing WordPress 404 handler
- Setting up the child theme so as to enable right-to-left WordPress?
- How do I get content of custom post type through post ID in wordpress
- Hooking new functions to actions + passing parameters
- WordPress template_include filter not working properly
- “The plugin generated 2694 characters of unexpected output…” on Plugin activation, CREATE TABLE sql command not working
- Do I need to prepare query before get_results(), get_row() and get_var()?
- WooCommerce: Add Payment Gateway Field to Webhooks [closed]
- Parsing php string in jquery [closed]
- doing an ajax request always outputs 0
- How to create a linked tag list in my sidebar
- What is the intended purpose of the _wp_attachment_context post meta key?
- Why the JavaScript code is ignored from wp editor?
- Why does my callback function not work with this custom filter hook?
- Get and insert order email address to the PHP template inside HTML text
- Integrating PHP into Javascript to display map markers with Google API – problem with wp_localize
- Send an email to specific adress when button is clicked?
- PHP version problem?
- Sort by page information by Ascending Numbers
- Embedding PHP in shortcode $content
- WordPress wp_redirect error
- single.php error
- php within html within php
- How do I display offsite database info on my wordpress site?
- Hide Heading if ACF Field is empty
- How to remove the message ‘We could not find any results for your search’ without changing template files and without adding posts/pages?
- Issue replacing forward slash in string
- Show site content based on user role
- PHP Parse error on WP-CLI, not on web server
- Get the id of the row from database on click of a button [closed]
- Plugin can’t write to database even though permissions appear correct?
- Modifying WP URL handing code?
- How to deal with a GET variable of ‘name’?
- I can’t set image ad fatured programatically
- Replace a single variable with add_filter
- Not work function add width and height at save post
- Inserting a class on before_widget if checkbox is checked
- Exclude multiple authors by ID – IF condition
- I want to hide “sold by” on certain pages with id page 43
- What is the correct way to search 3 custom fields only in WordPress?
- Used a code to revoke some dashboard menus for my contributors but for some reason it’s revoked me access to the editor [closed]
- How do I get the value of a current user’s custom field?
- Redirect user to a custom url after logged in
- Allow Comments by Default for Multiple Post Types
- HELP! Frontend User Profile Edit Won’t Update Email
- How to get User Avatar Image with link to Author and User name in Html Title tag?
- How to make a parent page for author.php?
- show desktop version of website if button is submited
- To call hook on a php external file
- Create new folder and upload files to custom folder via wp_handle_upload
- Set active class in a Php foeach
- ACF: Echo page title when checkbox is checked
- Hide the content before the more tag in the “single page”
- PHP code for link with text
- how to loop through blog posts in php
- How to add Paragraph Tags in WordPress using Visual Composer?
- PHP – Multiple variables in insert post array
- Search custom post type posts only by meta fields?