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 can i change email template for new user
- Enable page templates. How?
- Is it possible to override the result of get_template_part()?
- What’s the purpose of the paged.php file?
- Prevent comments_template() to load comments.php
- Page editor missing Templates drop down
- Custom templates folder
- What is the link to my default “archive” page?
- How to Rename a Template File?
- get page templates
- How do you check if a WordPress template file exist?
- Optimize Multiple Taxonomy Term MySQL Query?
- How to assign a class to a page with a custom template?
- Proper Javascript Implementation
- Guest author’s post not display in author template
- How to apply a custom template for posts by default?
- Delete duplicate rows from wordpress database where a column is duplicate in phpmyadmin
- Select User by Joining Multiple Meta Value Results
- Is there a way to check which template file is being loaded, if it is not a page template file?
- How to remove wp_link_pages() from template
- How can I get WP to use templates in lower-level subfolder?
- how to make a home page for wordpress custom theme
- You have an error in your SQL syntax – Help with query
- Generate Catalog Of Posts Based On Template
- Extending body classes in front- and backend
- How do I find the directory of a page template?
- Create WP_Query to search for posts by their categories or their parent/child categories
- Is there a way to set different post templates for parent posts and child posts in the same post type?
- Why write markup for index.php?
- LaTeX for WordPress strips codes in loop
- Having trouble with Template hierarchy. I Need to create a set of pages that drill down from states to specific locations
- How can I hardcode template selection?
- Changing layout programmatically
- How to identify which template WordPress’s default search-form retrieves in my theme
- How to use same page template if post status other than ‘publish’?
- Where is Number of Posts Set?
- How do I override the search template in a plugin?
- WordPress SQL injection
- Is there any way to write custom HTML is some .php file and then call it wherever necessary?
- How to redirect my custom template page to content-none.php if no posts found?
- Get URL of current post but not the page number
- Is template name always same as directory name?
- Single Post Breadcrumb not linking back to Custom Post Type Index?
- Form post to WordPress page = wrong template
- get_month_link uses what wordpress template?
- Load custom script on a single template
- Archive template limiting to 4 entries?
- Author template help. How to check if field exists in the profile?
- Can you use block patterns in block templates or insert them programmatically?
- WP redirect to custom login page if a user is not logged in
- Change default template in the block editor (Gutenberg)
- How do I create post template for different taxonomy
- Ip2location plugin in my template header?
- Queries take 120+ seconds on my large WordPress site
- Valid SQL query return empty
- mysql query – how to escape apostrophe?
- Import a header template from another theme
- Will placing custom templates in sub directory break any native WordPress functionality
- Brainstorm – Slow Query from Plugin Need to Speed It Up
- Adding text to the footer of each post based on tags or categories
- Blog page won’t show Blog template
- How can I abstract code out of a template by using functions.php
- Make Permalink go to specific template
- WordPress function.php on ZendFramework CMS
- Site Title appearing twice on live site
- Give user option to select full post index page or excerpted index?
- how to change already posted blog to custom template wordpress?
- WordPress change title with custom dynamic
- Display articles with a different template in the home page | Solved |
- template with multiple post loops for multiple widgets [duplicate]
- Random home page at each refresh between array of page IDs
- Do not trigger page 404 on custom template
- Print different parts of content in template
- How can I pass a variable from a template to header.php of a theme
- Page Template Selector Error
- Change Page Template Based on URL Rewrite in WordPress
- Trouble migrating custom post types from non-wordpress cms
- I want to display all related posts for a selected tag in WordPress
- How to do a MySql query in WordPress?
- WordPress Child Theme Template auth_redirect wrapper
- Show a custom template, no matter the page being viewed, if the user is not logged in
- printf, translation and the_author_posts_link()
- Search results in custom template
- Tag Posts showing in wrong places
- Parsing External Table Arguments
- front page won’t change templates
- Including 2 Negative Is_Template Conditionals in header.php [closed]
- Add custom card template to masonry layout using Essential Grid [closed]
- Where is the general html template file?
- 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
- WordPress template restored by mistake
- Unload templates; disable parent Template Parts using only “theme.json”