WordPress has a few useful options. You can get the homepage ID by using the following:
$frontpage_id = get_option( 'page_on_front' );
or the blog ID by using:
$blog_id = get_option( 'page_for_posts' );
Related Posts:
- Pagination Not working on Home Page with 2 Query
- The pagination on index.php doesn’t work on a first page
- Filtering posts from different categories into different section by doing WP_Query only once
- How to output the title of the blogs home page
- Posts limit on homepage (genesis framework)
- Where my home page and font options has gone?
- Excluding a category from frontpage but not from WP_Query
- Posts with at least 3 tags of a list of tags
- Get post count of current loop when using multiple queries on one page
- How to uniquely identify queries?
- Use WP_Query with a custom SQL query
- Pagination not working for Custom search form & custom result template
- Using next/previous_posts_link with customised search
- How to display most recent posts that haven’t already been displayed with WP_Query?
- What is the difference between these two custom queries?
- Display featured products through custom loop in WooCommerce 3 [closed]
- How to detect custom query inside `posts_where` hook?
- Is temporarily overwriting $wp_query a bad idea?
- Array Chunks and Inserting Varying HTML in WP_Query
- Filter user list that meta_value is empty
- Query wp_usermeta alongside wp_users
- How to output different posts per page?
- Multiple WP_Query loops with Pagination Not Working
- WordPress posts per page WP_Query
- WooCommerce Only OnSale Products Loop Snippet [closed]
- WP_Query times out
- ACF – Get lowest & highest value from field
- What format does the meta_query TIME type require?
- wp_query add arguments using array_push if variable met
- tax_query: Order by slug?
- WP_Query date_query – Use unix timestamp?
- WP_Query filter and order by meta ordering by wrong joined table
- WP_Query last five posts, simply ordered by meta_value
- WP_Query “OR”: Find posts by ID, Name or Post Title?
- What is the random string I am seeing when I use get_query_var?
- Querying A Post That Includes Two Taxonomies Using JSON Rest API
- WP_Query condition affects posts_per_page count
- WP_Query order result by date AND meta_value
- Order by title without taking into account ‘the’
- Set global $wp_query/$post variable for dynamic page generation
- Display tags with random thumbnail from selection of posts with that tag
- Is there a way to work with a specific the_field from an already queried post? [closed]
- slow WP_Query for non-admin user
- Changing sort order for presentation by Jetpack infinite scroll
- How to search for posts given post_content AND post_excerpt using WP_Query?
- Filter and Order by Multiple Custom Meta Values
- Meta Query relation “AND” then set array accordingly
- WP_Query Attachment adds additional attachment count and need to link attachment to post url
- Does the WP_Query ‘private’ argument for post status only apply to privately published content?
- Query most popular terms by taxonomy over 2 week period
- WordPress | Date not always appear [duplicate]
- WordPress posts for multiple years
- Query with meta_query and tax_query together not working properly
- Filter posts by comparing custom meta value against postdate
- Query posts that contain video?
- “paged” in WP_Query returns 0 posts
- How to show one post different from the rest?
- Reduce number of SQL queries inside WP_Query loop to fetch author data
- Count posts per taxonomy else change taxonomy if less than x number
- Combine 2 arrays in a query parameter
- Add ACF field in a query
- Set front_page programatically after user login via query, while leaving site option alone
- Running multiple WP_Query
- Check if searched number is within the post meta value
- How to split a post and intercalate elements from a loop
- How to echo woocommerce category name
- Find all product ID from array of customfield
- Printing a variable inside a custom WP_Query
- Notice thrown when creating numeric pagination on custom query
- and tag not working
- Hiding carousel indicators if there’s only one post
- add_query_arg to compare and display events from a certain date
- WP Query get only 1 post (sticky, not sticky etc)
- How to query all posts in CPT + only posts with custom tax in another CPT?
- WooCommerce sort by SKU
- Custom Meta Query doesn’t work the same on two site
- Order post by modified date
- Redirect logged in users from a custom post type archive page if they don’t have a specific role
- Order 2 meta_queries differently in WP_Query?
- Dynamically Update Page Content
- Optimal way to make tags in tax_query optional?
- How to count posts in loop with infinite scroll?
- the_post_thumbnail and multiple WP_Query
- I have 3 categories, i want to display on a loop the last 3 of every category
- Slow query when selecting with large meta query or post__in
- WP Meta Query at depth 2
- Rewrite rule pagination on different url levels
- WP_query for posts with same post type AND same post category
- How to solve this script problem in theme directory?
- WP_Query is being reset after tag (using chaining method)
- Pagination is not working on custom query inside a custom home page template
- return wp query results in a shortcode
- Sorting: custom query with orderby meta_value_num THEN by title
- confirm my booking with phone number
- Do not show a custom post if it belongs to a certain custom taxonomy
- Order by meta values
- Weird query with get_posts and WP_Query
- Adding arguments to WooCommerce Product Loop using AJAX
- How to hook the pre_get_posts filter via ajax call
- How can I echo out the user id in user meta?