I am new in WordPress. I have registered wp_query function through 'custom post type UI' and 'Advanced custom fields' plugin. And this is the code in the portfolio page.

<div id="tf-content">
<div class="container"><!-- Container -->
    <div class="row"><!-- Row -->
            $args = array(
                'post-type' => 'portfolio'
            $query = new WP_Query( $args );

        <?php if($query -> have_posts() ) : while( $query -> have_posts() ) : $query -> the_post(); ?>

        <a href= "<?php the_permalink(); ?>">
            <div class="col-md-4 col-sm-12 col-lg-3 col-xl-2">
                <div class="post-block" style= "margin: 0;"> <!-- Post #1-->
                    <div class="post-detail" style= "padding: 0;">
                        <div class="img-wrap">
                            <?php the_post_thumbnail(); ?>
        <?php endwhile; endif; wp_reset_postdata(); ?>

    </div><!-- end Row -->
</div><!-- End Container -->

I want this code to query all the 'portfolio' type custom post but I don't know why this code queries with general post but not portfolio type post. Please give me a solution for this.

Thank you in advance.


The post type argument needs to be written as post_type, but you are using it as post-type.

Change your argument to this:

$args = array(
    'post_type' => 'portfolio'
  • Thanks Jack for the quick reply. I changed the arguments but I don't know why it doesn't work yet. Do you see any other problems in my code? – M.S Shohan Jul 27 '17 at 14:35
  • You're welcome. That's strange. Are you sure you are loading the proper page and template? – Jack Johansson Jul 27 '17 at 14:43
  • Yes.... but after changing the argument array into 'post_type' it doesn't even query among general posts though I don't want them. I want the code to query among only the portfolio type posts. Do you have any suggestion for me? – M.S Shohan Jul 27 '17 at 14:52
  • If it doesn't query anything, it means that post_type is working, but there might be a mistype, since it can't find the post type portfolio. – Jack Johansson Jul 27 '17 at 14:54
  • I think it is happening for registering the post type with plugins. I have used advanced custom fields and custom post type UI plugins to register the post type. And there the post type/slug is 'portfolio'. Do you have any suggestion regarding the mistypes that may happen by a beginner wp developer? Thank you. – M.S Shohan Jul 27 '17 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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