Your question is vague: i’ll try to be as specific as possible.
The basic rule is: if you need to modify the default query, use pre_get_post
If you need to display another list of results than the one linked to your template url, use get_posts.
I find this documentation to be quite useful
http://developer.wordpress.com/2012/05/14/querying-posts-without-query_posts/
Doc on pre_get_posts
http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
Doc on get_posts
http://codex.wordpress.org/Template_Tags/get_posts
Related Posts:
- Is there a way to list all used/unused WP templates?
- How does wordpress blocks?
- Pagination issue with tag.php
- Dynamically generated URL and Content page
- How to add variables to a template
- Any way to insert text on page from a query results?
- How to use Class
in Java? - Get name of the current template file
- How do you find out which template page is serving the current page?
- How to change the default registration email ? (plugin and/or non-plugin)
- How do I get the size of an attachment file?
- Is there any way to use get_template_part() with folders?
- What SQL Query to do a simple find and replace
- the_date() not working
- Adding Page Attributes Metabox and Page Templates to the Posts Edit Page?
- How can i change email template for new user
- Any advantage to using get_header() over include(‘header.php’)?
- Enable page templates. How?
- Return only Count from a wp_query request?
- Is it possible to override the result of get_template_part()?
- Use [embed] filter in template files
- What’s the purpose of the paged.php file?
- How do you access the Product Short Description in a WooCommerce email template? [closed]
- Prevent comments_template() to load comments.php
- Get Featured Image via direct sql query
- Page editor missing Templates drop down
- Print WordPress template filename(s) for debugging
- How to prevent execution of default query, while preserving ability to use WP_Query in template?
- How to force TinyMCE in WordPress to replace newlines with tags and not with
- How to find the posts page (home page) programatically
- WooCommerce: Change template for single product page
- View WordPress page template usage (or unused)
- sql for querying post and their category
- How can I setup custom templates for a meta-data query
- Access Tables with number prefix
- Move Index to a page
- Blog template PHP [closed]
- Problem with permalink structure for WordPress custom post_type archive template
- Strange Behavior of Page Template Dropdown
- WordPress Template works until page becomes a child
- Parsing External Table Arguments
- Show page title just from the first child-page in template
- WordPress -> PHPBB look a like
- Problem with custom page template and permalink
- wordpress showing all posts instead of date range
- Index template and Home page
- Using wp config to connect to a DB from a plugin
- How to display page content and a list of posts on the same page?
- load_textdomain won’t load my .mo file
- How to know which page/file WordPress is expecting?
- AJAX requests within templates
- Page.php vs Single.php
- Make default template two columns?
- Read more button not working
- Force template on page load
- Query Concatenation
- WordPress query very slow on +/- 300k DB entries and 7 INNER JOIN
- front page won’t change templates
- pass dynamic value to page to pull in categorised post cards
- Implement HEAD and TITLE tags with DB DATA
- Output fields manually in Woocommerce email templates
- Custom Post Type Trouble
- Templates to use multiple time within page? [closed]
- Including 2 Negative Is_Template Conditionals in header.php [closed]
- files disappearing from template
- Add custom card template to masonry layout using Essential Grid [closed]
- Where is the general html template file?
- why does blog page ignore template [closed]
- Custom template pagination
- My homepage’s width has reduced and I can´t fix it [closed]
- html blog template to wordpress template
- SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta
- How to limit block activity (insertion/deletion) to inside of a Block Template on the Admin Screen?
- How to change post template
- templates page not showing on gutenberg editor
- Dynamic header and footer template inclusion: footer script not included
- How to load php templates from html page (block theme)
- WordPress template restored by mistake
- Unload templates; disable parent Template Parts using only “theme.json”
- Post archive is not using the assigned template
- In 2016 theme, how can I force all single attachment posts to use content-attachment.php rather than image.php?
- Remove posts that start with similar words (like a delete duplicate posts plugin)
- is it possible to get a list of URLs from post_content directly in a mysql query via phpadmin?
- Display A Post At A URL without Redirecting
- Category theme template becomes default template for child theme
- Custom API how to return int field
- Template adding to the page
- Add default meta data to a page/post template
- Every single link on my website opens to my last blog post
- Confused about editing the HTML in a template
- Adding new Template Parts in the Block Editor when using Classic Themes
- Problem in MySql query on WordPress [closed]
- WordPress “Blog” template hierarchy
- Copy a template part “header” that I want to duplicate and change a bit for a different page
- SQL errors when querying for something with apostrophes
- Get_Template_Part and Template files in TwentyTwentyFour Block Editor
- How to duplicate a template in wordpress site editor?
- How to force a Custom Post Type template by filename
- Difference Between Block Templates and Site Editor Templates
- order archive page by title in wp twenty twenty-four template