WordPress.org

Ready to get started?Download WordPress

Forums

More Types
How to show more types with template (6 posts)

  1. coastline1
    Member
    Posted 2 years ago #

    Hi,

    I am trying to display a list of my posts from a more-type. What code would i use to query posts from a particular type?

    http://wordpress.org/extend/plugins/more-types/

  2. playboi14
    Member
    Posted 2 years ago #

    Hello. Just a quick reply. Once you have created your new POST TYPE using the plugin, you need to go into one of your template files (for example I create a brand new template and only used the following code inside of it).

    <?php
    $args = array(
    		'post_type' => 'ourevent',
    		'posts_per_page' => -1
    );
    
    $posts = get_posts($args);
    foreach ( $posts as $post )
    {
           setup_postdata($post); ?>
           <a href="<?php the_permalink(); ?>">
           <h3>"<?php the_title();?>"</h3></a>
    } ?>

    Basically, you build an argument where your 'post_type' is set to the type you are looking for (replace 'ourevent' with the name of your type)

    We then make a new variable with that data (I called mine $posts) we are then calling 'get_posts' to get ALL of the posts with that type.

    Then you need to 'setup_postdata' as I have above and then simply print out the data from each post as you need it. In my example I have just printed out the title and made a link to the article.

    I hope this helps!

  3. miketurco
    Member
    Posted 1 year ago #

    I just can't get this to work. I copied your file, above, as a template and tried many different things.

    I have two custom fields. FirstName and LastName. Could you please provide an example of a working post template?

    Thanks!

    Mike

  4. playboi14
    Member
    Posted 1 year ago #

    Hey Mate,

    Ok well I don't use this plugin any more (I use 'Custom Content Type Manager' which is amazing for creating my own 'Types') but ill see if I can help you out anyway.

    Can you copy and paste your entire page template file? It should look something similar to this:

    <?php
    /**
    Template Name: OurEvents
    */

    get_header();

    /*Build an array variable to hold ALL of our event data */
    /*Change the 'ourevent' to your custom post type*/
    $args = array(
    'post_type' => 'ourevent',
    'posts_per_page' => -1
    );

    /*Get all the posts */
    $posts = get_posts($args);

    /*Loop through all of the posts in the custom post type*/
    foreach ( $posts as $post )
    {
    /*Set up the post data */
    setup_postdata($post); ?>
    <h3>"<?php the_title();?>"</h3>

    <!-- we create a variable and capture the 'EventLocation' in it, change this to the NAME of your individual variables that your trying to capture -->
    <p>
    <?php $EventLocation = get_post_meta($post->ID,'EventLocation',true);
    echo $EventLocation ?>
    </p>

    <p>$EventDescription = get_post_meta($post->ID,'EventDescription',true);
    echo $EventDescription ?></p>

    } ?>

  5. miketurco
    Member
    Posted 1 year ago #

    Wow, that looks like an awesome plugin and perhaps the things it does is appear to be the kinds of things I'm looking to do.

    I was using single.php from the Responsive theme. But before I start posting code and whatnot, I'm going to check out that plugin you're using. It looks like it will do the trick.

    My first project with this is going to be a simple phone book. Seems like a good place to start.

    Thanks!

    Mike

  6. playboi14
    Member
    Posted 1 year ago #

    Yea that other plugin is probably the best I've used for content type management.

    I use that version, plus I've modified it for my own use too.

    It gets quite complex, but just read all of the documentation and information you can online and it should work well for you.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags