Have you read this thread? Display all posts starting with given letter?
This wouldn’t be simple to do with WP_Query and that’s unfortunate because that would help preserve pagination.
// Rules
$args = ['post_type'=>'post','orderby'=>'name'];
// The Query
$query1 = new WP_Query( $args );
// The Loop
while ( $query1->have_posts() ) {
$query1->the_post();
echo '<li>' . get_the_title() . '</li>';
}
You could use wpdb
global $wpdb;
$results = $wpdb->get_results( "SELECT ID FROM wp_posts WHERE post_title LIKE 'B%';", ARRAY_A );
& then use WP_Query
// Rules
$args = ['post_type'=>'post','post__in'=>$results];
// The Query
$query1 = new WP_Query( $args );
// The Loop
while ( $query1->have_posts() ) {
$query1->the_post();
echo '<li>' . get_the_title() . '</li>';
}
pre_get_posts()
is another good one to use when doing this kind of thing.
Related Posts:
- How to get all author posts outside of author templates
- the_posts_pagination() not working in wpquery
- Custom query vars filters problem with pagination
- Remove Post if Advanced Custom Field is checked to fix paging
- How to work Woocommerce pagination inside shortcode?
- Load more posts using AJAX based on posts inside WP_Query
- Trying to get pagination working on WP_Query() post grid
- WordPress post pagination on custom template not working
- Pagination in category.php not functioning
- /page/2/ redirect to 404
- Getting paginate_links() ‘end_size’ to display none
- I can’t fetch query parameters ($_GET parameters) with get_query_var
- WP_Query | Help me create a search term with an ‘OR’ relation?
- Why does “get_option” pull in the older value in options.php, rather than the newer value, on submission of a form?
- get understrap pagination to work with custom query
- WP_Query use for a filter with multiple Taxonomies and Terms
- Duplicates with WP_Query loop
- Customized title tag for each page in pagination?
- How do I dynamically generate args for wp_query?
- Looking for most performant way to execute several similar WP queries within shortcodes
- How to get the Page Number of the Current Page in Single Post Pagination
- Get Current User Id Inside a Loop Returns 0 For a Shortcode
- Custom page archive query by url var calling page twice on one of my custom queries?
- How to query for posts with a null or blank post_name?
- WordPress pagination not working with search page
- How can I properly control the numbers and dots that appear in pagination?
- WP Query with custom Shortcode
- Increase returned number/pages on pagination
- How to use an associative array in post__in with WP_Query?
- Adding nofollow to a PHP generated Nav
- Using loop pagination on single.php
- How to show all pages in blog navigation?
- Add more button if more 8 items
- WordPress, AJAX and pre_get_posts using conditional tags
- Exclude posts based on meta value
- Pagination in plugin’s backend
- 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
- PHP code to use on next & previouspage links
- wp_query get the 2nd post
- How to create pagination for users list using custom array?
- How to add div blocks after certain set of post
- Convert a string into a decimal number for use in query
- Increment paged on WP_Query
- Hide posts if user is added to it WP_query
- How to hide posts of a specific custom category in WordPress?
- How to insert wp_users ->user login name to wp_terms when a new user registering?
- Order BY Most Liked And Published Between Previous Week Monday And Next Week Monday
- Modify main query before it run without pre_get_post
- WordPress WP_Query without query GET parameters
- Sort posts in a specific way
- Custom pagination (Previous / Next)
- posts_nav_link pulling in multiple post types
- displaying a fall back query if there’s nothing in the post-type category
- Pagination not working
- Modifying WP URL handing code?
- Free search and custom taxonomy query not providing the same result
- How do I reset $wp_query in a function?
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- wp_query with multiple arguments with AND
- Help to modify wp_link_pages()
- Replace a single variable with add_filter
- Is it possible to order posts using multiple meta queries, i.e. show posts from first meta query, then the second?
- Sending simple variable on single page to WP JSON
- How to exclude meta no index pages from wp_list_pages
- in_array not working on dev server but works on localhost
- meta_query search names when they have middle initials
- WP query posts BUT show the most recent and one per author
- Define global custom post
- get_filtered_term_product_counts – Get product terms if any products
- AJAX numerical pagination problem in TwentyFifteen-child theme
- Search for single post by 2 tags
- List all ACF field values across every post on one page
- Multiple Arrays for Custom Post Query using Boostrap accordions and ACF repeater fields
- Pagination – Previous link is not show and Next link sticks at page 2
- How can I get my pagination loop to display the correct number of total pages?
- Query to show average # of months all accounts with specific role have been active
- Woocommerce Related Product by 2 taxonomy
- Add a leading zero to pagination
- Query doesn’t display text data with apostrophes
- Get current_post in reverse order with pagination
- Querying posts from wordpress with 2 or more conditionals
- SQL Query Search page
- Can’t get data from audio media
- Display Year and Month from custom field + Age Calculator
- insert thumbnail image from php script
- WP_Query count of different meta key values [duplicate]
- Masonry layout within the loop
- rewrite_rule – working fine but broken for pagination
- How can i list all user registered on my website and have pagination [duplicate]
- Fix incorrect related posts code snippet
- How to add pagination for wordpress home page
- Pagination 404 on my index.php
- Blog Posts not sorted and pagination not adjusted after filtering some category
- How do I run the following script from my articles page?
- Execute multiple PHP Snippets causes error?
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- Three different queries on same page
- How to sort search result by post_title, then by post_content
- Why do I get a 404 error on my custom post type archive pagination?
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress