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 change the default registration email ? (plugin and/or non-plugin)
- Any advantage to using get_header() over include(‘header.php’)?
- What’s the purpose of the paged.php file?
- How to find the posts page (home page) programatically
- How to check if a shortcode exists?
- What is the link to my default “archive” page?
- Customizing get_the_excerpt() to specific length and “Read More” output.
- How do you check if a WordPress template file exist?
- Optimize Multiple Taxonomy Term MySQL Query?
- Load entire NextGEN gallery from single thumbnail?
- stop blog page from using index.php?
- How to hide/redirect the author page
- Gutenberg & Pre-formatted Templates: Core Block Attributes
- WooCommerce – Query for ordered products
- How to find if a post with custom_field == X exists?
- WP database error for comments_popup_link()
- Query WordPress database by registered date and role
- Get templated page/post content via the WordPress API
- Force all images to full size in page template
- Login WordPress website using wp-rest api
- Global variable set in the template’s header.php is unable to echo in footer.php
- Select Multiple meta_value from WP DB; Single Query
- How to Increment ID value within ACF Repeater Field Loop
- When a link doesn’t exist, how to tell WordPress what to do? (404 Error Page)
- WordPress Schema.org Markup. What value does it add?
- My SQL function to change user_name
- get_search_link() redirects to 404 template page
- CRUD operations using WordPress database API
- Why is variable not working on custom sql query using wpdb?
- How to get the most recent modified date of anything in the footer of my site?
- New custom nev not working [closed]
- How do I insert JS tracking code to a page with the WP editor?
- LaTeX for WordPress strips codes in loop
- How to remove the Template drop down, but keep Parent and Order
- Search results when none found – stay on page they were on
- how would I create a custom query to get all users, and a related post based on a postmeta field?
- Include Lumen/Laravel app in custom WordPress template
- Rewrite Rules to custom template
- Unable to display pagination links on custom category template
- 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?
- 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?
- 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
- 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
- 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()
- 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 change post template
- WordPress template restored by mistake
- Unload templates; disable parent Template Parts using only “theme.json”
- In 2016 theme, how can I force all single attachment posts to use content-attachment.php rather than image.php?
- How to force a Custom Post Type template by filename
- order archive page by title in wp twenty twenty-four template