As noted in the documentation for setup_postdata()
:
setup_postdata()
does not assign the global$post
variable so it’s important that you do this yourself. Failure to do so will cause problems with any hooks that use any of the above globals in conjunction with the$post
global, as they will refer to separate entities.
So the reason $my_post
doesn’t work is that functions you are using are depending on a variable named $post
, but it is not defined. setup_postdata()
does not set this variable. You need to do this yourself by defining $post
, which should be global $post
.
Related Posts:
- Grab the first paragraph of each post
- Single Page WordPress Theme – Using page templates
- First post of each category
- Finding Page Template and Displaying Content
- Some doubts about how to show posts in a custom theme?
- Echo all category names, apart from one
- how to get the post attachement image in full size?
- Change image size depending on page
- How can I use the WordPress Loop and Pagination in multiple instances but different scenarios throughout my site?
- first excerpt fine, subsequent post excerpts shift to the right instead of displaying vertically [closed]
- List categories of a post hierarchically?
- How Does One Create a Global Variable Repository
- How get the 10 most viewed pages (not post)
- How to close open divs in post loop
- Why am I getting posts back when I shouldnt
- Meaning of “if ( is_home() && ! is_front_page() )” snippet?
- The the_post_thumbnail without srcset?
- after_setup_theme always runs
- WordPress API Menu/Submenu Order
- What WP folder can I use to write files to?
- Get 10 posts from a WP_Query. If less than 10, get the remainder from elsewhere
- Why I can’t add a CSS style in this WordPress theme?
- register_sidebar ignores ‘id’ and ‘class’
- Display a different theme for not logged-in users
- Best practice (forward compatibility) for theme options
- Add colors to existing color palette without replacing it
- A two column loop with one lead post
- add_theme_support( ‘custom-header’ ) does not add option menu in dashboard
- Returning Variables back into a template
- new theme permissions don’t allow me to edit
- Getting Permalink within the loop
- Which theme foundry has clean coded themes, where code is poetry [closed]
- What page should I use for a contact form?
- Retrieve data using wpdb to use for customizer controls
- How can a Theme Contain no Header File or Footer File?
- Some translations do not work in my template class
- Link won’t show using the_permalink();
- WordPress not registering Theme Customization Section
- How to remove a file included in parent theme with locate_template() via child theme?
- qTranslate with my own theme and settings
- Stylesheet not linking
- How to control layout of posts on page?
- Override template file i subfolders
- Theme Development for WordPress Multisite Installation
- Include Parent functions.php in Child Theme functions.php
- How to show user online status on their posts?
- create category on theme setup
- WordPress get_template_part() function not working
- Where am I doing wrong in my theme menu?
- How can my theme allow users to take advantage of advanced html tags in posts
- Best way to develop a new theme on a live site, with new content? [closed]
- How do I make the most minimal vanilla theme possible with nothing but raw content?
- Can I Set Up Session in WordPress Custom Page
- How to list articles by year based on url?
- Set a featured image as a replacement to the header image
- Custom theme: How to call archive-post.php for viewing blog posts
- Theme Customizer not displaying saved values in wp_head (CSS)
- How can I prevent posts with no title showing up in my query?
- How can I hard code my sidebar?
- Thesis -style Navigation
- How can I wrap all blog posts image with
- where is real values of variables?
- Issue when posting updates/changes to wordress
- Valid SQL query not returning results
- StoreFront WordPress theme: How can i create a new Home page with Custom design same as template [closed]
- A post with a clear:both in its css destroy the theme design, and the sidebar is moved to the bottom
- Create theme for mobile phones and tablets only?
- Never actually adding the action? Or do I have to call the action?
- Retrieve WordPress’ the_content() with jQuery
- How to hide custom sidebar on mobile
- Recommended sidebar / content widths
- Theme Checker Text Domain
- How to copy page/post from one theme to another?
- Not sure how to debug this npm install error. This is a wordpress theme that comes with a built-in gulp/webpack task automation [closed]
- Add class every 4 post like , class_1, class_2, class_3, class_4 and class_1, class_2, class_3, class_4
- Why front-page.php doesn’t show content of file instead shows loop
- How to make updatable custom WordPress theme?
- How can I access variables from theme in child theme? [closed]
- Creating a Single Page Theme correctly
- Is it possible to echo a woocommerce prouct attribute discription?
- Child theme menu not appearing in Twenty Seventeen
- How do I remove header/page-title image in farvis theme? [closed]
- How to link post image to post link?
- WordPress Twenty-Fourteen: How to Remove Home Page Header Image from Other Pages
- On wordpress, how do i require specific dimensions from user uploads only
- WordPress Theme Developments – Start from another theme
- Slider should be display in home template [closed]
- Modify comments_popup_link output
- Best way to access variables in template markup
- Can you create a custom page with content in the center already defined?
- How to migrate the menu from the site on my own theme in WordPress?
- RSS feed url showing page not found. How to solve it?
- How to convert that page to a wordpress template? [closed]
- Toolbox theme using printif statement – help needed understanding code block
- Not Found when using activity stream as front page with BuddyPress
- php file child theme directory not overriding parent theme php file [duplicate]
- How to Create a Multi Purpose Theme?
- Display Page featured Image as well as Posts featured Image
- Custom Single Page Portfolio Theme [closed]
- How do I send out an update for my custom wordpress theme?