Skip to main content
improved code formatting
Source Link
s_ha_dum
  • 65.5k
  • 13
  • 84
  • 174

I am currently working in a project in wordpress.

Here i have to get all posts from two custom post types namely pt1, pt2.

But here i want to display posts with random post type(pt1, pt2).

Example)

I want to display first post from pt1, next from pt2 and again pt1 and next pt2 and so on...

How can i do this. Any help? This is the code:

$args = array(

 $args = array(

'posts_per_page'   => 5,    

'orderby'          => 'post_date',

'order'            => 'DESC',   

'post_type'        => array('pt1', 'pt2'),  

'post_status'      => 'publish'

 ); 

$posts = get_posts( $args );

$num=1;

foreach($posts as $post) {

    if( $num % 2 == 0 )             

        echo $post->post_title.$post->post_type;

    else    

        echo $post->post_title.$post->post_type;

    $num++;

}

I am currently working in a project in wordpress.

Here i have to get all posts from two custom post types namely pt1, pt2.

But here i want to display posts with random post type(pt1, pt2).

Example)

I want to display first post from pt1, next from pt2 and again pt1 and next pt2 and so on...

How can i do this. Any help? This is the code:

$args = array(

'posts_per_page'   => 5,    

'orderby'          => 'post_date',

'order'            => 'DESC',   

'post_type'        => array('pt1', 'pt2'),  

'post_status'      => 'publish'

 ); 

$posts = get_posts( $args );

$num=1;

foreach($posts as $post) {

    if( $num % 2 == 0 )             

        echo $post->post_title.$post->post_type;

    else    

        echo $post->post_title.$post->post_type;

    $num++;

}

I am currently working in a project in wordpress.

Here i have to get all posts from two custom post types namely pt1, pt2.

But here i want to display posts with random post type(pt1, pt2).

Example)

I want to display first post from pt1, next from pt2 and again pt1 and next pt2 and so on...

How can i do this. Any help? This is the code:

 $args = array(

'posts_per_page'   => 5,    

'orderby'          => 'post_date',

'order'            => 'DESC',   

'post_type'        => array('pt1', 'pt2'),  

'post_status'      => 'publish'

 ); 

$posts = get_posts( $args );

$num=1;

foreach($posts as $post) {

    if( $num % 2 == 0 )             

        echo $post->post_title.$post->post_type;

    else    

        echo $post->post_title.$post->post_type;

    $num++;

}
added 449 characters in body
Source Link
Balas
  • 621
  • 5
  • 17

I am currently working in a project in wordpress.

Here i have to get all posts from two custom post types namely pt1, pt2.

But here i want to display posts with random post type(pt1, pt2).

Example)

I want to display first post from pt1, next from pt2 and again pt1 and next pt2 and so on...

How can i do this. Any help? This is the code:

$args = array(

'posts_per_page'   => 5,    

'orderby'          => 'post_date',

'order'            => 'DESC',   

'post_type'        => array('pt1', 'pt2'),  

'post_status'      => 'publish'

 ); 

$posts = get_posts( $args );

$num=1;

foreach($posts as $post) {

    if( $num % 2 == 0 )             

        echo $post->post_title.$post->post_type;

    else    

        echo $post->post_title.$post->post_type;

    $num++;

}

I am currently working in a project in wordpress.

Here i have to get all posts from two custom post types namely pt1, pt2.

But here i want to display posts with random post type(pt1, pt2).

Example)

I want to display first post from pt1, next from pt2 and again pt1 and next pt2 and so on...

How can i do this. Any help?

I am currently working in a project in wordpress.

Here i have to get all posts from two custom post types namely pt1, pt2.

But here i want to display posts with random post type(pt1, pt2).

Example)

I want to display first post from pt1, next from pt2 and again pt1 and next pt2 and so on...

How can i do this. Any help? This is the code:

$args = array(

'posts_per_page'   => 5,    

'orderby'          => 'post_date',

'order'            => 'DESC',   

'post_type'        => array('pt1', 'pt2'),  

'post_status'      => 'publish'

 ); 

$posts = get_posts( $args );

$num=1;

foreach($posts as $post) {

    if( $num % 2 == 0 )             

        echo $post->post_title.$post->post_type;

    else    

        echo $post->post_title.$post->post_type;

    $num++;

}
Source Link
Balas
  • 621
  • 5
  • 17

Display posts in random post types

I am currently working in a project in wordpress.

Here i have to get all posts from two custom post types namely pt1, pt2.

But here i want to display posts with random post type(pt1, pt2).

Example)

I want to display first post from pt1, next from pt2 and again pt1 and next pt2 and so on...

How can i do this. Any help?