Found it: The posts I’m working with are instances of custom posts, and the default get_posts() function assumes that posts are just, well, posts. So it wasn’t finding them, and was properly returning “none”.
Solution: I added some code to my theme’s function.php file, like so:
function set_up_theme() {
...other stuff
function mytheme_pre_get_posts ()
$query->set('post_type', 'my_custom_post_type');
}
add_action('pre_get_posts', 'mytheme_pre_get_posts');
}
Better ways or places to set this up are welcome, but it seems to be doing the trick.
Related Posts:
- How to create tag.php
- Strange Behaviour with is_home()
- Disable Woocommerce product tags display by alphabetical order
- How to get and set the post tag value within WP Query from URL?
- Pagination issue with tag.php
- Organize template parts and page templates in folders in regards of template hierarchy
- How can I include custom category and tag base in template files?
- Conditional template tag for buddypress pages
- which template does wp_ tag_ cloud point to?
- small problem in the article ()
- Editing the tag pages and using templates
- Is it possible to return a specific tag archive/template as one of the search results?
- Tag Posts showing in wrong places
- How do I get the size of an attachment file?
- tag.php doesn’t work with tags on a custom post type post?
- How to get slug of current category in taxonomy template?
- Using WordPress templating for HTML emails
- I put my blog on a subpage, how do I get page title?
- Outputting Canonical Resource URLs Across a Multisite Network?
- Restrict a search to a custom post type
- Test if page is child and has children, if so echo child pages also on grandchild pages
- How did you incorporate WooCommerce in your own WordPress theme?
- Correct process for a new Page Template?
- A shared custom taxonomy between two custom post types
- Creating a custom category page with pagination
- how to limit and display tag?
- Same template for all the terms of a taxonomy
- Modifying searchform.php and search.php to have two kinds of searches
- Create a WordPress template without navigation and footer
- Template redirect is_tax() not working
- Hide Front-End Admin Bar Including 32 px Spacing
- Passing variables to template parts
- Show template loaded
- Change directory where get_header(), get_footer() and get_sidebar() look for templates
- How can I make my custom templates respect permissions?
- How to format shortcode’s HTML in external file
- How to replace WordPress sidebars (widget areas) with Gutenberg
- Unable to include a template
- Turning on the 404 page on localhost
- Checking for page templates in child theme
- Is there an action hook that fires just before a template is loaded?
- post edit button on front end
- What’s the equivalent of front-page.php for a custom static page?
- Stylesheet comment header: Which header names are mandatory? [duplicate]
- How to add posts list to a page template?
- Valid HTML in Template Part
- Are Category or Tag Archive Pages Possible?
- Why do I get the same excerpt for all items in my RSS feed?
- What is this code trying to do? It was the cause of my 20s TTFB
- get_post_metadata() undefined when used in loop in RSS template
- the_excerpt producing empty output
- Problem when linking out to separate file within foreach loop
- Conditional tags or Multiple files
- Getting term description in single post template
- Cannot edit style.css from admin panel, because the template is looking for style.min.css
- Can I add a default Block to my custom theme?
- Remove post templates from the selection box menu when creating a single post
- How to convert the WordPress meta box Page Attributes->Page Template dropdown to radio buttons?
- global variables in templates
- Real Time Page Template Preview in WP Admin [closed]
- Best practice to update the file header.php
- page-{slug}.php vs. template-{slug}.php
- Understanding the Template hierarchy
- wp_enqueue_style and different styles for blog template
- get_header(), get_footer() from plugin template
- Problem creating a custom category page with pagination
- If Posted After Date
- how can I add a “read more” tag directly in the template?
- Update template without undoing all my edits?
- How to display specific child page template in wordpress
- The wordpress website is showing ‘w’ while it loads and in the footer
- how to properly include or get file contents in a wordpress theme
- Is there a wordpress template like this [closed]
- Including template pages within another template?
- Why won’t the action hook wp_head accept parameters?
- trouble calling different header.php for home.php
- the_post() in RSS feed
- How Add Code in Page Index Custom Template?
- Editing my loop-page.php causes posts to show on all pages
- Template part including not working
- Parent/Child themes – both CSS files loaded
- Template and URL parameter problem
- get_users by role returns all users
- Validating Error with submit button
- How can I alter a post?
- What is the purpose of the $before and $after arguments on the the_title() function?
- Remove ” Browse Category : ” from Archive title
- Custom Post Type tag taxonomy “Page Not Found”
- showing tag beside catagory
- When to use content-pagename.php?
- Using external file with WP_USE_THEMES set to false causing 404
- Current URL path variable
- How to install a wordpress website template on an existing website?
- Why is my no-results.php template moving my sidebar and footer into the main container?
- Given a page ID, how to display entire page (header/content/footer/sidebars) from a plugin hook
- Any way to insert text on page from a query results?
- Show page title just from the first child-page in template
- How to know which page/file WordPress is expecting?
- AJAX requests within templates
- Page.php vs Single.php