• I have created posts with Custom Posts and the regular Posts by WordPress. However, the custom posts does not appear on the website. Only the regular posts appears.

    Here I have created Custom Posts:
    https://i.stack.imgur.com/lZFnP.png

    Here I have created posts with the regular WordPress posting:
    https://i.stack.imgur.com/oXTvu.png

    Here are the 2 latest posts within the category 9 (Featured) supposed to be shown:
    https://i.stack.imgur.com/iMTlx.png

    As you see, it does not show the one made with Custom Post. This is not the only example, but this is the easiest one to explain.

    <div class="col-md-12 myeluft">
                <?php
                    $catquery = new WP_Query( 'cat=9&posts_per_page=2' );
                    while($catquery->have_posts()) : $catquery->the_post();
                ?>
                <div class="featured-post">
                    <ul>
                        <li>
                            <div class="col-md-5 featuredimage myeluftned">
                                <?php the_post_thumbnail( 'singlepost-thumb' ); ?>
                            </div>
                            <div class="col-md-7 myeluftned">
                                <h2 class="nomargintop blacklink">
                                    <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
                                </h2>
                                <div class="light offblack">
                                    <?php the_content(); ?>
                                </div>
                                <a href="<?php the_permalink() ?>" rel="bookmark">
                                    <button class="btn thin luft" type="button">Se prosjekt</button>
                                </a>
                            </div>
                        </li>
                    </ul>
                </div>
                <div class="col-md-12">
                    <hr class="myeluft clearboth">
                    <?php endwhile; ?>
                </div></div>

    Anyone?

    I will post detailed if you want, I just need to know what you want to know.

    Is there a function I need to make Custom Fields Post to work?

    Plugin used: Types

    I have created posts with Custom Posts and the regular Posts by WordPress. However, the custom posts does not appear on the website. Only the regular posts appears.

    Here I have created Custom Posts: Custom Posts

    Here I have created posts with the regular WordPress posting: WordPress Posts

    Here are the 2 latest posts within the category 9 (Featured) supposed to be shown: 2 latest posts within the category 9

    As you see, it does not show the one made with Custom Post. This is not the only example, but this is the easiest one to explain.

    Code

    <div class=”col-md-12 myeluft”>
    <?php
    $catquery = new WP_Query( ‘cat=9&posts_per_page=2’ );
    while($catquery->have_posts()) : $catquery->the_post();
    ?>
    <div class=”featured-post”>

    </div>
    <div class=”col-md-12″>
    <hr class=”myeluft clearboth”>
    <?php endwhile; ?>
    </div></div>
    Anyone?

    I will post detailed if you want, I just need to know what you want to know.

    Is there a function I need to make Custom Fields Post / Types to work?

    Suggestions:

    • Functions.php, something is wrong here
    • Types, something is wrong the setup

    Question also asked here: https://wordpress.stackexchange.com/questions/193188/posts-with-custom-fields-does-not-appear

    https://www.ads-software.com/plugins/types/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Dear oleav

    When you using custom WP_Query like this:

    new WP_Query( 'cat=9&posts_per_page=2' );

    Yo use default value for “post_type” witch is ‘post’.

    see more: https://codex.www.ads-software.com/Class_Reference/WP_Query#Type_Parameters

    You should use (I prefer array not query string):

    $args = array(
        'cat' => 9,
        'posts_per_page' => 2,
        'post_type' => 'any',
    );
    new WP_Query($args);

    But remember, that any retrieves any type except revisions and types with ‘exclude_from_search’ set to true.

    or:

    $args = array(
        'cat' => 9,
        'posts_per_page' => 2,
        'post_type' => array(
            'post',
            '<custom-post-name>',
        ),
    );
    new WP_Query($args);

    Cheers,
    Marcin

    Thread Starter oleav

    (@oleav)

    Thank you. That solved the problem ??

    Just another question, how would you have edited this so this showed all post types:

    <?php $the_query = new WP_Query( 'posts_per_page=50' ); //Check the WP_Query docs to see how you can limit which posts to display ?>
    <?php if ( $the_query->have_posts() ) : ?>
        <div id="isotope-list">
        <?php while ( $the_query->have_posts() ) : $the_query->the_post();
        $termsArray = get_the_terms( $post->ID, "category" );  //Get the terms for this particular item
        $termsString = ""; //initialize the string that will contain the terms
            foreach ( $termsArray as $term ) { // for each term
                $termsString .= $term->slug.' '; //create a string that has all the slugs
            }
        ?>
        <div class="<?php echo $termsString; ?> item col-md-3"> <?php // 'item' is used as an identifier (see Setp 5, line 6) ?>
            <h3><?php the_title(); ?></h3>
                <?php if ( has_post_thumbnail() ) {
                          the_post_thumbnail();
                    } ?>
        </div> <!-- end item -->
        <?php endwhile;  ?>
        </div> <!-- end isotope-list -->
    <?php endif; ?>

    I have tried inserting an array, but it didnt work:

    $anyposttype = array('post_type' => 'any');
    $termsArray = get_the_terms( $post->ID, "category", $anyposttype);  //Get the terms for this particular item

    Dear oleav

    See documentation:
    https://codex.www.ads-software.com/Function_Reference/get_the_terms

    Retrieve the terms of the taxonomy that are attached to the post.

    This function get taxonomies assign to current post in loop.

    M

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Posts created with Types does not appear’ is closed to new replies.