The WP_Query
class does not generate HTML markup. WP_Query
will query the WordPress content, and provide some data back. So using WP_Query
and the sprintf()
PHP function, the HTML markup can be generated (untested):
$args = array(
...
);
$query = new WP_Query( $args );
$html="";
while ( $query->have_posts() ) {
$query->the_post();
$saved_html .= sprintf( '<a href="%s">%s</a>', esc_url( get_the_permalink() ), esc_html( get_the_title() ) );
}
echo $saved_html;
You could also use PHP’s output buffering if you prefer, but sprintf()
is the quickest/simplest implementation.
Related Posts:
- echo var into wp_query
- WP query with variables gives no result for specific user
- Pass variable from one function to another
- Get value from shortcode to do something
- How to use $query->set with post__in?
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- Loading the same WP_Query in two different wordpress .php templates
- How to prevent WP_Query function from returning all posts when empty?
- Dynamic content based on a URL parameter
- Display a specific category of products in shop page and disable code for specific actions
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- Add more button if more 8 items
- How to store post ID’s in cookie or session to display the same posts later
- WordPress, AJAX and pre_get_posts using conditional tags
- Get users that likes the post
- PHP, Creating a dynamic variable
- get_posts() and WP_query limits ‘AND’ conditions to a maximum of 6 for meta value queries in WordPress
- How to modify a global variable in a function and use it on another function?
- Exclude posts based on meta value
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Custom query, checking values of multiple meta keys
- auto-populating custom nav with all items from custom post type
- inserting a post from an extern php file but post content doesn’t show on wp site
- Remove echo from shortcode
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- WordPress theme options error
- Security for data obtained from the database
- Fatal error: Call to a member function query() on a non-object
- Get posts from multiple post type
- Is it possible to retrieve all posts with a certain value for metadata?
- How to get all author posts outside of author templates
- WP_Query fails despite having 1 post
- Variable not staying set
- Create a Blog Template Page
- unable to use ‘new WP_Query’ in AJAX call
- wp_query get the 2nd post
- Exclude posts with specific metadata from search?
- How to get post ID in a Page?
- Display an image if odd number of posts in grid
- How to retrieve the data from the sever and displaying it in a page?
- WordPress function and string as variable?
- Assign custom parameter to each post in query
- Create a WordPress shortcode using PHP [duplicate]
- How to add div blocks after certain set of post
- How to pass a PHP $_GET variable and fetch/output it?
- Creating WordPress Shortcode with Variable
- How to overwrite orderby with add_query_var
- How to put a form with php code into a variable or shortcode?
- Apply class to every third list item? [duplicate]
- persist a variable set in header.php all the way down to footer.php
- Why doesn’t PhotoSmash plugin play well with wp_query?
- Get access to variable from previous pageview, excluding ajax-calls
- get_the_ID() in the footer returns wrong value
- Trouble inputting variable into WP query
- the_posts_pagination() not working in wpquery
- How to deal with too many $_POST variable conditions from ajax request at backend? [closed]
- How to override url params with rewrite rules vars?
- What is the alternative code to if (isset ($_POST) && !empty ($_POST) to avoid warnings?
- WP_Query: getting posts where custom field exists
- How to show meta value code HTML after x paragraph
- How to pass a variable to get_template_part that’s updated every time the template part is called?
- Form search query – displaying ACF “Post Object” field as results
- Insert page content into another page with a changed variable
- WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank
- Pass Variables or Variable Place-Holder from Editor to PHP
- Convert a string into a decimal number for use in query
- How to display SQL query that ran in WC_Order_Query?
- get_the_ID() doesnt work
- Array to string conversion on array_map
- Store metakey value as an array
- Increment paged on WP_Query
- Target post_date_gmt if it’s empty or not set
- How to access or parse key/values that have “string”
- Hide posts if user is added to it WP_query
- Custom route and query
- change the default order of posts only for specific categories
- How Do I Find & Remove H1 From Site-Title-Wrapper? [closed]
- Getting posts to exclude from array
- Get all posts as an array ID => Name
- How to hide posts of a specific custom category in WordPress?
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- How to insert wp_users ->user login name to wp_terms when a new user registering?
- javascript variable to wordpress php variable
- Post not populating for custom post type based on category selection
- Passing an array into WP_Query as a variable
- Custom query vars filters problem with pagination
- Custom post type permalinks do not appear using the link functions
- WordPress meta_query >= &
- extract serialized array to use for wp-query
- Order BY Most Liked And Published Between Previous Week Monday And Next Week Monday
- WP_Query multiple post results
- Modify main query before it run without pre_get_post
- WordPress WP_Query without query GET parameters
- Sort posts in a specific way
- How to reference PHP in Javascript
- Do not duplicate posts with multiple categories in multiple loops
- Infinite Loop – WP_Query
- How can I split my query result in 2 arrays?
- Store and Change Session variable – PHP SESSION VARIABLE
- array_rand not working correctly?