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
- When should you, and when should you not, use wp_list_pluck()?
- Display random categories on the front page (Finding and Editing Theme Functions)
- Woocommerce add to simple product attribute programmatically [closed]
- opening links in new tab using – add_filter( ‘the_content’, ‘make_clickable’);
- AJAX handler throws 400 (Bad request) – why?
- How to display the_post_thumbnail if a post has one or otherwise display the first image in a post?
- Most elegant way to enqueue scripts in function.php with foreach loop
- Set default options for inserting media
- Default or Preset Content for Custom Post Types
- Remove tag on my RSS Feed
- How to add a rel attribute to images that contains their categories?
- Adding WooCommerce to a Custom Theme – not working [closed]
- How do you output custom code between posts in the loop?
- 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]
- Post thumbnail relative link and HTML modify
- Custom Shortcode, functions PHP WP_Query loop
- 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?
- PHP files included in functions.php don’t seem to work
- How Can I Expand the WordPress Customize window without any Plugin?
- Set quantity of woocommerce product on page visit [closed]
- str_replace function in theme
- Right way to update widget on dynamic new input field
- How to customly read JWPlayer’s “Playlist” items by using its “playlistid”?
- Twentyten Child Theme: header images display messed up in admin panel
- 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]
- Best practices regarding the creation of custom widgets?
- Word Press – Dynamic Content [closed]
- 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
- The Loop not looping?
- Custom HTML markup
- Use a shortcode to display custom meta box contents
- How do I pull excerpts from pages?
- Output loop to function return?
- Add attribute only to first image of every post via functions.php
- Genesis Framework: How to exclude a specific author from archive custom loop
- Problem with calling custom function in a foreach loop
- The_content and Preg_replace in loaded Iframe [closed]
- Using functions.php to include code that’s processed inline
- two search forms on the same page
- Insert a field with PREG_REPLACE – strange behaviour
- New checkbox in custom widget isn’t saving data
- Linking Javascript in functions.php file
- how to display a page before the home page
- Function to check if custom page is used by page?
- Simplest Way to Build Custom Archives Page?
- Woocommerce Variable Product Dropdown for Custom Shop Template
- How to remove font awesome from loading in wp theme
- How to replace ACTION url from original wordpress login form?
- Header menu aligned right on all pages except for single-post page [closed]
- update_user_meta as multiple value but with same meta key
- Hide author info in single posts by certain users
- Shortcode to insert default text and change one word throughout it?
- Prevent function from triggering on current page
- I want to customize the_posts_navigation function by replacing prev and next with images
- How Can I Concatenate A String With One Of My Custom Field Value Before Saving The Post?
- How would I correctly implement a new if statement in a child functions file?
- WordPress Ajaxifying not working properly
- WordPress function with attribute pass to template
- True email confirmation for registration (keeping unvalidated users from user table)
- Code executes outside of Loop while same code gives ‘Uninitialized string offset’ notice inside a while loop
- Adding A New Widget to WordPress Disables the Existing Widgets
- How To Show Shortcodes In WordPress Custom Fields?
- Help! Need a different logo on my main page from my other pages
- Display page number on custom page title function
- Only seems to be displaying one child when there are supposed to be multiple
- How to replace words in my posts and saved new words
- How do I integrate my Child Theme into a Custom Template?
- Shortcode to eliminate and replace with
- Add functionality to post editor
- custom post with loading script per single post
- Integrate WP Tiles into existing loop (index.php) and theme
- Check if excerpt is empty at loop-portfolio
- Get Value of Custom Field
- restrict access to specific urls on a specific period of time
- child_of not working while searching
- Why does modifying my functions.php file always result in a server error
- Why don’t some template tags work when querying information on single.php?
- Parse error: syntax error, unexpected ‘endforeach’ (T_ENDFOREACH) in [closed]
- Removing Facebook contact field from user contact not working
- How do grab the main loop, with conditions, and output via shortcodes
- How do I add functionality to images?
- Get full slug for a WordPress Post
- Problem with removing characters “<” – WpAllImport
- How to crop image in WordPress with aspect ratio for any size of image
- multible shortcodes (for differnt values) with one function
- Customizer cuistom CSS Priority ordre Issue
- Copy and Modified WooCommerce function is_coupon_valid [closed]