Couple of issues are seen here –
- You have hooked a function in a template file whereas such code should go in
functions.php
instead or you can directly put the code of this function in the template. - You does not seem to be getting value of
$post
inside this function. - Both the
return
statements should be removed and justecho $html;
should be placed just after thewp_reset_postdata()
in your current code.
Related Posts:
- How to display page content in a page template?
- Single page theme
- Single page theme that uses pages for the content
- Trying to list out child pages with WP_Query
- Front End Sorting Questions
- What are the differences between “Latest Posts” and “Static Page”?
- WP_Query doesn’t get sticky post at the top, when used in a page template
- Pagination of a WP_Query Loop in a child-page page template
- list pages using page.php and NOT page-{slug}.php
- Get pagination working for custom loops within page templates
- How is WP_Query parsed to determine which template to request?
- WordPress Pagination changes my template
- add_filter(‘query_vars’) not working in custom template
- Need to convert string of term ids into comma separated integers for use in an arguments array
- Pass $page_id to new WP_Query
- Pagination on template page for custom query redirecting to index.php
- Create a page template for “top rated posts” but show full content and not just a list
- WP_Query returns different results from get_posts() [closed]
- inserting content of 1 Post to in another with a template hierarchy
- How to generate feed for custom template
- WP_Query with multiple orderby NOT working with ASC and DESC, what’s wrong?
- Pagination for custom loop on custom page template is not displaying anything
- How to create Page templates for showing Blog posts in different layouts?
- Excluded category from loop
- Posts limit on homepage (genesis framework)
- Page template doesn’t display simple HTML if inserted into other page?
- How to separate two columns from one content on a page template?
- What’s the best way to make a blog page on WordPress?
- How to use custom page for all posts with custom url, call another directory?
- INNER JOIN custom tables – SQL Query
- Pagination Shows Up But Won’t Work on Custom Gallery Page
- How to exclude posts by ID within a category/archive loop
- WP Query works outside a function, not inside a function
- How can I use a specific wordpress page template if certain words are used in page title [closed]
- Fetching $_POST from Page Template into functions.php
- Using URL variables on a custom WP_Query
- Pagination is not working on custom query inside a custom home page template
- Passing query variables to a custom page template
- Need help setting up a search form for wordpress [duplicate]
- When importing a database any page with a wp_query in doesn’t work
- Having trouble using this post category query on multiple pages?
- Adding css tweak based on page template
- WordPress pagination returns the same posts
- order by numeric value for meta value
- numberposts? showposts? posts_per_page?
- $GLOBALS[‘wp_the_query’] vs global $wp_query
- Some doubts about how the main query and the custom query works in this custom theme?
- Set Alias for meta_query arguments in get_posts()
- How to query only for products with status “in stock” in WooCommerce? [closed]
- Does WordPress sanitize arguments to WP_Query?
- WP_Query meta_query where meta value ends in space
- Highlighting Sub topic in a post?
- How to get any tag ID
- WP_Query with many meta_query arguments taking a long time to load
- Slow speed and high CPU usage for my code. How to improve it?
- Multiple queries on Home Page – page load/site speed issue
- WordPress custom archive page
- query attachments of parent page if attachments of current page are smaller than …
- Show all parents and children in custom post type in right order
- Why is this coming back as null? Thats wrong. There is one post
- Retrieve featured image (thumbnail) url from multiple posts with one query
- Retreaving all images attached to current post
- wp_query() get_col error
- How to select posts from one category but exclude posts in another category?
- Order a query result by a numeric meta key even if it does not exist, but put the posts with meta key first
- How can you get first post, last post and post count in a category?
- WP_query posts closest to todays date
- difference between like ‘%%%var%%’ and ‘%var%’
- WP Query Category Atribute Not Working
- How to orderby multiple meta fields if some fields are empty
- WordPress custom post type with meta – how to retrieve with wp_query
- Order by meta value (numeric value lower to higher)
- Wp_query calculate points
- get data match with extra field value using wp_query for custom post
- WP_Query for a taxonomy with different taxonomy types
- Append URL query to next post link in custom query
- Executing query_posts after wp_insert_post
- Redirect Search to Form When No Product Results Are Found
- wp_query posts with custom fields number smaller than
- Related Posts Excluding Certain Categories
- Max Posts and Memory Limit
- WordPress | WP_Query does not return anything with s=a
- WP_Query Pagination
- Using Ajax and WP_Query to load more posts on category page fails
- I have problems with the search query using multiple post types
- meta_query compare > not working
- WP_Query about meta_key and its array value
- Query string order by custom field
- Paging works correctly on local version, but not live?
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- Paginate nested query of child posts
- Get Current CPT taxonomy category in shortcode
- Custom Content Slider stop duplicate
- Sort Posts with custom meta key by default which is currently set as optional
- wp_query pagination links producing 404
- How return normal search result using wp_ajax action for wordpress
- Custom post types loop on a page template
- Pagination problem with multiple loops on the same page
- WP_Query – meta fields numeric
- How to query posts from single post format on Genesis framework