Try to get two different arrays of posts and loop through array A. Before get post data of A element get random element from array B.
For example:
$array_a = ['post_id_a1', 'post_id_a2', 'post_id_a3'];
$array_b = ['post_id_b1', 'post_id_b2', 'post_id_b3'];
foreach ( $array_a as $a_post_id ) {
$is_b_should_displayed = mt_rand( 0, 1 );
if ( $is_b_should_displayed && $b_length = count( $array_b ) ){
$b_to_show = mt_rand( 0, $b_length - 1 );
// show random B post
unset( $array_b[ $b_to_show ] );
$array_b = array_values( $array_b ); // to reorder array after unset
}
// show A post
}
Or in same way create array C, and then loop through C to display posts.
There is no warranty all B will displayed, so, if you need it, you could loop through B (if at least 1 element exist) after main A loop
Small note: rand
using for key orderby
not to order according to wp docs.
Hope it helps
Related Posts:
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- Wp_query: sort by PHP variable
- Wp Query sort order from custom MetaBox
- Sort Order for a Custom Query in a Post Type Archive Not Working
- Select All in Parent Category, Group by Child Category?
- Custom Post Type, WP_Query and ‘orderby’
- Sorting a query by custom field date
- Number of pages – multiple (custom) post types
- Custom Post type sort order not working in the admin area
- WP_Query post at custom position
- query order by date on custom type: wrong order
- Re-order posts in query after
- Sort by two dates. Default entry date and custom field if present
- How to query different post types in specific order?
- Sorting multiple custom post types without a meta key/value pair by sort order
- Previous/Next Link by Meta Value in CPT
- Crafting WP_Query array, sort by date
- WP_Query order by custom field, then randomly order some of results
- How to do WP_Query with two meta fields with orderby clause
- Order Custom Post Type by Custom Field Value
- Sort entries by date mixing two post types
- Change sort order when using ‘orderby’ => ‘type’
- Custom post type sorting: alphabetical order
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- WP_Query of custom post type sorted by meta_key has unexpected results
- WP_Query not resetting after wp_reset_postdata
- Sort results without WP_QUERY?
- Post ordering not working with custom field
- Displaying Portfolio Filter by Category Order (alphabetically)
- Sorting the Loop by Taxonomy Value
- How to order query results based on if a custom field has been populated, then the order by the date of the post?
- Sort custom posts by date and then by taxonomy
- Display Parent-Child Posts in specific order by comparing IDs in array
- How can I sort the results of a REST API response by the title of a connected custom post type?
- Order posts alphabetically with numbers but some of the posts has numbers in the title
- How to sort by multiple values in a nested WP_Query
- Custom post type order by post_title
- SEARCH QUERIES – REVERSE OUTPUT
- How to use multiple orderby conditions on query search results? (orderby one post type, relevance)
- Using Orderby and meta_value to order natural/alphanumerical
- sorting in wp query based on custom field value
- How to sort custom post’s category by id from the theme’s function.php?
- WP Query with multiple post types ordered by custom meta date then published date
- Orderby modified only for specific post types
- Custom post order when using OR relation
- How do I sort post listing by child post count?
- 404 on Pages for Custom Post Type & Query_Posts
- WP_query orderby not working after WP4.0 update [closed]
- Query order by meta value force specific tag first
- Order Wp Query by earliest of 3 dates meta query
- Sort CPT by taxonomy AND THEN by custom field
- Display all posts in a custom post type, grouped by a custom taxonomy
- Query by post title
- How to check if a WP_Query has data
- Ordering Posts List By Taxonomy Terms?
- Retrieving 3 latest post from each of 5 different custom post types
- Get latest 4 post on a custom post filtered by category
- Wp-query causing problems with the_content();
- wp_query and comment_parent – select only posts with top level comments
- Multiple Archive Pages for Custom Post Types AND Taxonomies
- Display Posts of a Category in Alphabetical Order (Custom Post Type)
- Ordering Custom Post Types with WP_Query
- Filter posts with meta_query NOT IN where value has multiple values
- is_main_query() not working for WP REST API
- Taxonomy Archive: Display only one post per term from separate custom taxonomy
- Loop through Custom Post Type, and then show children within each iteration
- Rewrite and custom post type: order by custom field not working
- wp_query check if integer exists in custom field’s array
- orderby rand is not working for a custom post types
- Display featured image from one CPT within another CPT query
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- Add ‘last’ class to second post in featured post loop
- Ascending Order is not Working in Custom Post Type Listining
- sort post types by amount of views
- Trouble with pagination
- Select2 AJAX and WP Query Returns ALL and does not filter
- List categories, subcategories and posts from custom taxonomy and custom post type
- How to query Posts from a custom post type which contains a custom taxonomy?
- filter the_content, custom post type, and wp_query
- Loop for custom-post-type comparing taxonomy terms for “related” posts?
- Get_the_term_list inexplicably adds values in foreach
- Single parent post lists child posts with pagination
- Custom Form / Search with Custom Post Type Data
- Query to show post current day
- Using ACF values in nested WP queries for CPT with date values in the past
- how to display posts content on the custom css popup by clicking on each title on the sidebar?
- How do I insert a custom post type query after a certain number of recent posts and then resume recent posts?
- WP_Query for custom taxonomies showing posts from non-specified terms?
- how to display new private message to users?
- Make pagination work as a carousel (custom query)
- WP_Query with all posts in one custom post type and only posts in another custom post type with a specific category
- Search result based on URL
- subtracting the current post form then whole loop, which is generating all CPT titles
- Displaying WordPress posts from post and custom post type in custom taxonomy
- Manually build WP_Query
- Loop with Custom Post Type and Taxonomies
- New WP_Query not isolating custom post types on front-page template
- Pagination not working on homepage
- How to query custom post then display sections by meta value
- Order custom post type is beign ignored