The insideds of a function is separated from the global things. Therefore the variables, set by other processes are not reachable/useable inside a function until you made them so, with, for example global
keyword for a var.
So
Add
the_post();
after the function’s {,
or add
global $post;
and use $post->ID
instead of the_ID
and so on.
I also recommend you to read some books on programming PHP.
Related Posts:
- Creating loop within functions.php
- Add multiple custom fields to the general settings page
- When should you, and when should you not, use wp_list_pluck()?
- Display random categories on the front page (Finding and Editing Theme Functions)
- Is it possible to remove the “standard” post format?
- Woocommerce add to simple product attribute programmatically [closed]
- Issue with get_theme_mod returning a blank value instead of the saved value
- How to remove row-actions from pages table?
- Show modified time if post is actually modified
- opening links in new tab using – add_filter( ‘the_content’, ‘make_clickable’);
- AJAX handler throws 400 (Bad request) – why?
- Modify search function in WordPress (TwentyTwelve)
- How to display the_post_thumbnail if a post has one or otherwise display the first image in a post?
- How to customize search result page title?
- Auto delete WordPress images/thumbnails (all sizes) and featured after X days/hours, or similar?
- How to fix a theme with page.php Default Template that accidentally deleted?
- Most elegant way to enqueue scripts in function.php with foreach loop
- Removing Unnecessary Text from Admin Menu without CSS
- Set default options for inserting media
- Default or Preset Content for Custom Post Types
- Remove tag on my RSS Feed
- Display WordPress Search
- How do I change parameters without changing the core
- WordPress – thumbnail image from youtube (function and loop)
- Problem with extract() with custom shortcode
- How to add a rel attribute to images that contains their categories?
- delete an array element when its date expires
- add sidebar area to header of child theme
- Preferred Use of home_url()?
- Adding WooCommerce to a Custom Theme – not working [closed]
- Custom function for user register in wp?
- A snippet after every image
- Function to show only first instance of shortcode
- How do you output custom code between posts in the loop?
- Automatically insert php function into post $the_content
- Theme-Config tab in admin Pannel?
- How to Add a Random Custom Gravatar in the WordPress Comments?
- Delete pages and Create default pages for all new network sites
- Actions according to image type and size
- Display WooCommerce subscriptions for user [closed]
- How to use max and min values of custom fields
- Post thumbnail relative link and HTML modify
- Refactor create_function
- Custom Shortcode, functions PHP WP_Query loop
- Filtering posts by category name based on page’s slug
- adding custom classes for tables
- Pass Shortcode Attribute to footer Script
- How to mass-delete inline styles in WordPress custom post type automatically?
- How would go about if I just want a temporary function?
- Remove the deleted users avatar from list
- How to call custom function from functions.php in site-wide template files?
- Customizer field value into functions.php variable
- PHP files included in functions.php don’t seem to work
- 2 Loops, Only Displaying 1 Loop in Both Loops
- How Can I Expand the WordPress Customize window without any Plugin?
- Set quantity of woocommerce product on page visit [closed]
- wp_dropdown_categories and custom attribute
- str_replace function in theme
- Automatically wrap multiple images in div
- Ajax not working properly
- is_customize_preview() like function to check if Customizer “Live Preview” in JavaScript
- Right way to update widget on dynamic new input field
- How to customly read JWPlayer’s “Playlist” items by using its “playlistid”?
- Having a Function Inside of the Loop
- Include default functions and methods
- Hard-coding custom menu elements for menu manager
- Twentyten Child Theme: header images display messed up in admin panel
- Getting different functions data while using while loop in wordpress
- How can I remove the main description text box in a Woocommerce product editor page? I only use the “Product short description” text box [closed]
- How can I modify all existing tags while keeping the urls themselves?
- Best practices regarding the creation of custom widgets?
- IF Statement on Button to make it complete and “uncomplete” based on user action / click
- Create a new query in function.php to filter blog posts
- Gravity Forms Button Text
- Find resources dynamically loading and change or add to the url
- When sale price is 0.00 show only regular price
- Unable to login using username
- Word Press – Dynamic Content [closed]
- Limit length of first excerpt in the loop
- Insert image in WordPress with HTML5 tag and caption function
- how can I just add to parent theme function(s) instead of redeclaring whole the function
- Default Custom Field Value Automatically Update
- Multiple Loops Meta Data
- Move Custom Fields on General Settings Page to New Location
- Skeleton Child Theme Add Icon Bar to Header Flex Grid
- Why doesn’t is_page(id) work in functions.php?
- different style sheet for just one page template
- Condition OR for current user ID
- The Loop not looping?
- How to retrieve the current post’s generated featured image size?
- Custom Behavior when Adding New Custom Post Type in Dashboard
- Where do I store custom functions that call custom page template files?
- While loop with an exception after a count is reached
- Why There Is No “get content by ID” Function
- Custom HTML markup
- Use a shortcode to display custom meta box contents
- How do I pull excerpts from pages?
- Output loop to function return?
- Wp-query Order By problem
- Create custom function for hero image