0

I have a custom post type:products to have my post from my custom post type i have changeed these codes

<?php
    $post_count = 1;
?>
<?php if (have_posts()) : while ( have_posts() ) : the_post() ?>

to

?php
    $post_count = 1;        $args = array(          'post_type' => 'products'       );      $products = new WP_Query( $args );
?>
<?php if ($products->have_posts()) : while ( $products->have_posts() ) : $products->the_post() ?>

I have done same things for the archive.php also. But

Now what i want to do i wont to get posts from different post types on my front page. Not any. And when i chose a category to get posts i want to get from different post types. Not any thispart inside of archive.php How we can do that.

3 Answers 3

1
function namespace_add_custom_types( $query ) {
  if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
    $query->set( 'post_type', array(
     'post', 'post_type1', 'post_type2'
        ));
      return $query;
    }
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );

it worked realy good.

0

you can try wordpress query like

$args = array(
 'post_type' => 'any'
);
$query =WP_Query($args);

if( $query->have_posts() ){
  while($query->have_posts()){
    the_post();
    $hide_post_type = array(
      'attachment'
    );    

    // hide post type which you do not want to show
    if( in_array( get_post_type(),$hide_post_type))
      continue;

    //show your post of any type
  }
}
3
  • [code] <?php $post_count = 1; $args = array('post_type' => 'any'); $query =new WP_Query($args); ?> <?php if($query->have_posts()): while($query->have_posts()): the_post() ?>[/code] ı got erroe
    – lospicos
    Dec 8, 2013 at 13:58
  • How i can decide teh custompost categories than?
    – lospicos
    Dec 8, 2013 at 14:09
  • Fron any created othe rproblems for me. thats whay speciag post types more than 1.
    – lospicos
    Dec 8, 2013 at 14:18
0

I solved the problem by adding these code to fucntions.php

function namespace_add_custom_types( $query ) {
  if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
    $query->set( 'post_type', array(
     'post', 'your_post_type'
        ));
      return $query;
    }
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.