the_permalink() echoes the output, and so does the_title() by default. So you should use get_permalink() and get_the_title():
$html .= '<h3><a href="' . get_permalink() . '">' . get_the_title() . '</a></h3>';
Or use the_title() with the third parameter set to false to return and not echo the output:
$html .= '<h3><a href="' . get_permalink() . '">' . the_title( '', '', false ) . '</a></h3>';
Update: The return $html; (in your original non-edited question) was actually outside the function and that would result the shortcode to give you no output! So make sure that it’s inside the function in your actual code. 🙂 And for secondary/custom WP_Query instances like your $loop variable, you just need to call wp_reset_postdata() and not wp_reset_query() since secondary queries don’t touch the (global) $wp_query variable. Unless of course, in your code, you modified that variable. But why would you do that.
Related Posts:
- Object of class WP_Query could not be converted to int inside shortcode
- WP_query shortcode inside acf Repeater breaks the repeater loop
- Display List Of Posts Containing a Relationship Field Value [ACF]
- Using OR conditions in meta_query for query_posts argument
- ACF Relationship Field Search Filtering [closed]
- Last post ordered by publish date using WP_Query on front page
- ACF datepicker meta_query Compare Dates in m/d/Y g:i a – Not in Ymd Format
- WordPress meta_query and order by custom field
- Shortcode returns escaped HTML tags
- Revolution Slider Orderby Two Custom Fields
- meta_query with array as value
- query posts in functions.php and update a field
- Can certain (site-crashing) limitations on WP_Query in shortcode be overcome?
- Minimising number of queries on a page when using Advanced Custom Fields
- Query Posts depends on custom field inside repeater field using acf
- ACF Relationship + WP Template Parts
- Minimising Database Queries when using Advanced Custom Fields
- If two first numbers exist in wp_meta_query value
- WP_Query meta_query >= date
- Category attribute not working in custom shortcode
- How To Fix WP Query Returns Results But Shouldn’t?
- Custom query based on meta key – Reduce three states to two in results?
- Include custom field in Ajax search WordPress
- What is the random string I am seeing when I use get_query_var?
- How to get all child pages in their parent page?
- Any number in meta key (wp query)
- How do I run through a WordPress loop called from a filter function?
- Orderby is working with one query but not with other
- Is there a way to work with a specific the_field from an already queried post? [closed]
- How to Union two different conditions in one WP_Query
- Excluding pages in WP_query using ACF
- How to do a wp_query with two acf-fields, sorting on one of them
- Using Advanced Custom Field for file upload, how do I load the file url
- Multisite wp_query & switch_to_blog issue
- Stuck in the query loop
- Get all fields inlcuding “ACF” (Advanced Custom Fields) columns in wp_query
- WP_Query with meta_query dosen’t return results
- Shortcode for latest -not expired- posts
- Gallery shortcode numerical sorting
- How to filter a query by date in a shortcode?
- How should I approach changing the template & $query as part of a shortcode’s execution?
- Include post content of linked posts in search
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Merge 2 custom post type posts and taxonomy terms and sort ascending
- Shortcode Not Working in Slider When Added To Post Title
- JSON – Create rest api endpoint for Advanced Custom Fields
- Shortcode for custom query not returning results when attributes are added
- Expecting statement error from php loop using ACF plugin
- Custom query filter by ACF date custom field
- Using a Shortcode to List Posts from Multiple Categories
- embedding shortcodes in php template
- How to get specific string in explode array?
- WP Query orderby ACF boolean values and ACF field value
- Optimising WP_Query with ACF Fields
- Woocommerce Shortcode which displays a table with product data
- Oxygen Repeater Advanced Query
- ACF: How to query for a given value count of an array like field? (e.g.: How many rows has a `flexible_content` field?)
- WP_Query – display posts by custom field and order by another
- WP_Query for distinct meta values
- Group Product Types
- WPQuery Date and ACF
- Excluding posts from search results page with meta query not working
- Populate select list with meta values from all posts of a Custom Post Type
- Form checkbox value going to dynamic URL
- ACF: How can I publish values of ACF fields in a loop while using wp_query?
- WP Query by 4 different taxonomies
- WP Query by variable custom field
- Query for getting posts with their custom fields data in WordPress
- How to get taxonomy image attached to a Post Type WordPress
- How to display a post(by id) along with css in a page?
- How to rearrange posts based on input field values added by WordPress “Advanced Custom Fields”
- WP Query with meta queries
- Custom query showing all acf field values instead of the one searched
- Pre get posts sort by meta key returns no results if meta key does not exist
- How to query wordpress with array of meta_values?
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- ACF: using two loops, the_field returns field content from another loop
- pages shortcode filtering by category
- WP_Query & shortcode : Return 3 articles from a category WordPress
- How can I modify standard search query to include also ACF custom fields values?
- Query by Category and Custom Field – Shortcode
- How to take parameters from a function and make them editable as attributes in a shortcode
- How to modify WP Query to target the first most recent post to adjust content
- WP_Query within save_post doesn’t include the item that triggered the action?
- Geo location query inside wp_query?
- return wp query results in a shortcode
- More efficient query to display posts in same sub-category?
- Having Trouble Running Query From Shortcode Using Tribe’s Events Plugin
- Query posts filter not working
- Creating array to compare custom field values
- Display all custom meta field values from the database using ACF Repeater
- Shortcode does not display pagination [duplicate]
- How to write a query-function as a query-shortcode?
- shortcode with $atts with strange results
- I want to place a post before all others from an ACF boleen field
- Use value from meta key array for use in WP_Query
- How to prevent WP query searching in executed shortcodes
- How to use meta_query to retrieve posts from multiple custom post type
- WP_Query filtering in ACF field containing dates
- Include custom post type that matches taxonomy field in another custom post type