Skip to main content
deleted 1 characters in body
Source Link
Tom J Nowell
  • 60.6k
  • 7
  • 77
  • 147

To do an OR rather than an AND, you would need custom logic, and it would be a hassle, but an unnecessary one!

Instead of trying to get the posts AND the category, you should do 2 individual queries to grab what you want, so grab all the video posts, put them in an array, then grab all the posts in the video category, add those to the same array, then print out what you've got.

Kind of like putting oranges in your shopping cart, then putting bannanas in, rather than looking endlessly for a box that has both oranges and bannanas together

$slides = array();
$found_posts = array();
// get the video posts
$query = new WP_Query(
    array(
        'post_type' => 'videos',
        'posts_per_page' => -1
    )
);
if($query->have_posts()){
    while ( $query->have_posts() ) {
        $query->the_post();
        $carousel_slide = 'put your slide content here, so probably an <li> element or something?';
        $found_posts[] = $post->ID;
        $slides[] = $carousel_slide;
    }
    wp_reset_postdata();
}

// get the video category
$query = new WP_Query(
    array(
        'category_name' => 'video',
        'posts_per_page' => -1
        'post__not_in' =>  $found_posts,
    )
);
if($query->have_posts()){
    while ( $query->have_posts() ) {
        $query->the_post();
        $carousel_slide = 'put your slide content here, so probably an <li> element or something?';
        $slides[] = $carousel_slide;
    }

    wp_reset_postdata();
}

// we should now have all our slides in the $slides array so lets print them out

echo implode('',$slides);

You will need to modify this line which appears twice:

$carousel_slide = 'put your slide content here, so probably an <li> element or something?';

So that it contains the slide html for the post, so I imagine it will likely be an li element, some calls to grab the featured image, etc but that's beyond the scope of this question ( which is regarding queries, not how to setup JCarousel slides and featured images ).

To do an OR rather than an AND, you would need custom logic, and it would be a hassle, but an unnecessary one!

Instead of trying to get the posts AND the category, you should do 2 individual queries to grab what you want, so grab all the video posts, put them in an array, then grab all the posts in the video category, add those to the same array, then print out what you've got.

Kind of like putting oranges in your shopping cart, then putting bannanas in, rather than looking endlessly for a box that has both oranges and bannanas together

$slides = array();
$found_posts = array();
// get the video posts
$query = new WP_Query(
    array(
        'post_type' => 'videos',
        'posts_per_page' => -1
    )
);
if($query->have_posts()){
    while ( $query->have_posts() ) {
        $query->the_post();
        $carousel_slide = 'put your slide content here, so probably an <li> element or something?';
        $found_posts[] = $post->ID;
        $slides[] = $carousel_slide;
    }
    wp_reset_postdata();
}

// get the video category
$query = new WP_Query(
    array(
        'category_name' => 'video',
        'posts_per_page' => -1
        'post__not_in' =>  $found_posts,
    )
);
if($query->have_posts()){
    while ( $query->have_posts() ) {
        $query->the_post();
        $carousel_slide = 'put your slide content here, so probably an <li> element or something?';
        $slides[] = $carousel_slide;
    }

    wp_reset_postdata();
}

// we should now have all our slides in the $slides array so lets print them out

echo implode('',$slides);

You will need to modify this line which appears twice:

$carousel_slide = 'put your slide content here, so probably an <li> element or something?';

So that it contains the slide html for the post, so I imagine it will likely be an li element, some calls to grab the featured image, etc but that's beyond the scope of this question ( which is regarding queries, not how to setup JCarousel slides and featured images ).

To do an OR rather than an AND, you would need custom logic, and it would be a hassle, but an unnecessary one!

Instead of trying to get the posts AND the category, you should do 2 individual queries to grab what you want, so grab all the video posts, put them in an array, then grab all the posts in the video category, add those to the same array, then print out what you've got.

Kind of like putting oranges in your shopping cart, then putting bannanas in, rather than looking endlessly for a box that has both oranges and bannanas together

$slides = array();
$found_posts = array();
// get the video posts
$query = new WP_Query(
    array(
        'post_type' => 'videos',
        'posts_per_page' => -1
    )
);
if($query->have_posts()){
    while ( $query->have_posts() ) {
        $query->the_post();
        $carousel_slide = 'put your slide content here, so probably an <li> element or something?';
        $found_posts[] = $post->ID;
        $slides[] = $carousel_slide;
    }
    wp_reset_postdata();
}

// get the video category
$query = new WP_Query(
    array(
        'category_name' => 'video',
        'posts_per_page' => -1
        'post__not_in' =>  $found_posts
    )
);
if($query->have_posts()){
    while ( $query->have_posts() ) {
        $query->the_post();
        $carousel_slide = 'put your slide content here, so probably an <li> element or something?';
        $slides[] = $carousel_slide;
    }

    wp_reset_postdata();
}

// we should now have all our slides in the $slides array so lets print them out

echo implode('',$slides);

You will need to modify this line which appears twice:

$carousel_slide = 'put your slide content here, so probably an <li> element or something?';

So that it contains the slide html for the post, so I imagine it will likely be an li element, some calls to grab the featured image, etc but that's beyond the scope of this question ( which is regarding queries, not how to setup JCarousel slides and featured images ).

added 432 characters in body
Source Link
Tom J Nowell
  • 60.6k
  • 7
  • 77
  • 147

To do an OR rather than an AND, you would need custom logic, and it would be a hassle, but an unnecessary one!

Instead of trying to get the posts AND the category, you should do 2 individual queries to grab what you want, so grab all the video posts, put them in an array, then grab all the posts in the video category, add those to the same array, then print out what you've got.

Kind of like putting oranges in your shopping cart, then putting bannanas in, rather than looking endlessly for a box that has both oranges and bannanas together

$slides = array();
$found_posts = array();
// get the video posts
$query = new WP_Query(
    array(
        'post_type' => 'videos',
        'posts_per_page' => -1
    )
);
if($query->have_posts()){
    while ( $query->have_posts() ) {
        $query->the_post();
        $carousel_slide = 'put your slide content here, so probably an <li> element or something?';
        $found_posts[] = $post->ID;
        $slides[] = $carousel_slide;
    }
    wp_reset_postdata();
}

// get the video category
$query = new WP_Query(
    array(
        'category_name' => 'video',
        'posts_per_page' => -1
        'post__not_in' =>  $found_posts,
    )
);
if($query->have_posts()){
    while ( $query->have_posts() ) {
        $query->the_post();
        $carousel_slide = 'put your slide content here, so probably an <li> element or something?';
        $slides[] = $carousel_slide;
    }

    wp_reset_postdata();
}

// we should now have all our slides in the $slides array so lets print them out

echo implode('',$slides);

You will need to modify this line which appears twice:

$carousel_slide = 'put your slide content here, so probably an <li> element or something?';

So that it contains the slide html for the post, so I imagine it will likely be an li element, some calls to grab the featured image, etc but that's beyond the scope of this question ( which is regarding queries, not how to setup JCarousel slides and featured images ).

To do an OR rather than an AND, you would need custom logic, and it would be a hassle, but an unnecessary one!

Instead of trying to get the posts AND the category, you should do 2 individual queries to grab what you want, so grab all the video posts, put them in an array, then grab all the posts in the video category, add those to the same array, then print out what you've got.

Kind of like putting oranges in your shopping cart, then putting bannanas in, rather than looking endlessly for a box that has both oranges and bannanas together

$slides = array();
$found_posts = array();
// get the video posts
$query = new WP_Query(
    array(
        'post_type' => 'videos',
        'posts_per_page' => -1
    )
);
if($query->have_posts()){
    while ( $query->have_posts() ) {
        $query->the_post();
        $carousel_slide = 'put your slide content here, so probably an <li> element or something?';
        $found_posts[] = $post->ID;
        $slides[] = $carousel_slide;
    }
    wp_reset_postdata();
}

// get the video category
$query = new WP_Query(
    array(
        'category_name' => 'video',
        'posts_per_page' => -1
        'post__not_in' =>  $found_posts,
    )
);
if($query->have_posts()){
    while ( $query->have_posts() ) {
        $query->the_post();
        $carousel_slide = 'put your slide content here, so probably an <li> element or something?';
        $slides[] = $carousel_slide;
    }

    wp_reset_postdata();
}

// we should now have all our slides in the $slides array so lets print them out

echo implode('',$slides);

To do an OR rather than an AND, you would need custom logic, and it would be a hassle, but an unnecessary one!

Instead of trying to get the posts AND the category, you should do 2 individual queries to grab what you want, so grab all the video posts, put them in an array, then grab all the posts in the video category, add those to the same array, then print out what you've got.

Kind of like putting oranges in your shopping cart, then putting bannanas in, rather than looking endlessly for a box that has both oranges and bannanas together

$slides = array();
$found_posts = array();
// get the video posts
$query = new WP_Query(
    array(
        'post_type' => 'videos',
        'posts_per_page' => -1
    )
);
if($query->have_posts()){
    while ( $query->have_posts() ) {
        $query->the_post();
        $carousel_slide = 'put your slide content here, so probably an <li> element or something?';
        $found_posts[] = $post->ID;
        $slides[] = $carousel_slide;
    }
    wp_reset_postdata();
}

// get the video category
$query = new WP_Query(
    array(
        'category_name' => 'video',
        'posts_per_page' => -1
        'post__not_in' =>  $found_posts,
    )
);
if($query->have_posts()){
    while ( $query->have_posts() ) {
        $query->the_post();
        $carousel_slide = 'put your slide content here, so probably an <li> element or something?';
        $slides[] = $carousel_slide;
    }

    wp_reset_postdata();
}

// we should now have all our slides in the $slides array so lets print them out

echo implode('',$slides);

You will need to modify this line which appears twice:

$carousel_slide = 'put your slide content here, so probably an <li> element or something?';

So that it contains the slide html for the post, so I imagine it will likely be an li element, some calls to grab the featured image, etc but that's beyond the scope of this question ( which is regarding queries, not how to setup JCarousel slides and featured images ).

added 454 characters in body
Source Link
Tom J Nowell
  • 60.6k
  • 7
  • 77
  • 147

To do an OR rather than an AND, you would need custom logic, and it would be a hassle, but an unnecessary one!

Instead of trying to get the posts AND the category, you should do 2 individual queries to grab what you want, so grab all the video posts, put them in an array, then grab all the posts in the video category, add those to the same array, then print out what you've got.

Kind of like putting oranges in your shopping cart, then putting bannanas in, rather than looking endlessly for eacha box that has both oranges and bannanas together

$slides = array();
$found_posts = array();
// get the video posts
$query = new WP_Query(
    array(
        'post_type' => 'videos',
        'posts_per_page' => -1
    )
);
if($query->have_posts()){
    while ( $query->have_posts() ) {
        $query->the_post();
        $carousel_slide = 'put your slide content here, so probably an <li> element or something?';
        $found_posts[] = $post->ID;
        $slides[] = $carousel_slide;
    }
    wp_reset_postdata();
}

// get the video category
$query = new WP_Query(
    array(
        'category_name' => 'video',
        'posts_per_page' => -1
        'post__not_in' =>  $found_posts,
    )
);
if($query->have_posts()){
    while ( $query->have_posts() ) {
        $query->the_post();
        $carousel_slide = 'put your slide content here, so probably an <li> element or something?';
        $slides[] = $carousel_slide;
    }

    wp_reset_postdata();
}

// we should now have all our slides in the $slides array so lets print them out

echo implode('',$slides);

Instead of trying to get the posts AND the category, you should do individual queries for each

$slides = array();
$found_posts = array();
// get the video posts
$query = new WP_Query(
    array(
        'post_type' => 'videos',
        'posts_per_page' => -1
    )
);
if($query->have_posts()){
    while ( $query->have_posts() ) {
        $query->the_post();
        $carousel_slide = 'put your slide content here, so probably an <li> element or something?';
        $found_posts[] = $post->ID;
        $slides[] = $carousel_slide;
    }
    wp_reset_postdata();
}

// get the video category
$query = new WP_Query(
    array(
        'category_name' => 'video',
        'posts_per_page' => -1
        'post__not_in' =>  $found_posts,
    )
);
if($query->have_posts()){
    while ( $query->have_posts() ) {
        $query->the_post();
        $carousel_slide = 'put your slide content here, so probably an <li> element or something?';
        $slides[] = $carousel_slide;
    }

    wp_reset_postdata();
}

// we should now have all our slides in the $slides array so lets print them out

echo implode('',$slides);

To do an OR rather than an AND, you would need custom logic, and it would be a hassle, but an unnecessary one!

Instead of trying to get the posts AND the category, you should do 2 individual queries to grab what you want, so grab all the video posts, put them in an array, then grab all the posts in the video category, add those to the same array, then print out what you've got.

Kind of like putting oranges in your shopping cart, then putting bannanas in, rather than looking endlessly for a box that has both oranges and bannanas together

$slides = array();
$found_posts = array();
// get the video posts
$query = new WP_Query(
    array(
        'post_type' => 'videos',
        'posts_per_page' => -1
    )
);
if($query->have_posts()){
    while ( $query->have_posts() ) {
        $query->the_post();
        $carousel_slide = 'put your slide content here, so probably an <li> element or something?';
        $found_posts[] = $post->ID;
        $slides[] = $carousel_slide;
    }
    wp_reset_postdata();
}

// get the video category
$query = new WP_Query(
    array(
        'category_name' => 'video',
        'posts_per_page' => -1
        'post__not_in' =>  $found_posts,
    )
);
if($query->have_posts()){
    while ( $query->have_posts() ) {
        $query->the_post();
        $carousel_slide = 'put your slide content here, so probably an <li> element or something?';
        $slides[] = $carousel_slide;
    }

    wp_reset_postdata();
}

// we should now have all our slides in the $slides array so lets print them out

echo implode('',$slides);
Source Link
Tom J Nowell
  • 60.6k
  • 7
  • 77
  • 147
Loading