0

What is the code i have to put in the page to show the posts from custom post type?

2
  • 2
    It would be helpful if you could offer more details in your question. Commented Feb 10, 2011 at 17:00
  • 2
    There's an example here: codex.wordpress.org/…
    – t31os
    Commented Feb 10, 2011 at 18:06

2 Answers 2

3

Easy: modify the query... (and add some comment on top to make a template out of this...)

$query_default = new WP_Query( array(
     'orderby'      => 'menu_order'
    ,'order'        => 'ASC'
    ,'post_type'    => 'custompost' // THIS IS WHAT YOU'RE SEARCHING FOR
    ,'post_status'  => 'publish'
) );
    if ( $query_default->have_posts() ) :

        while ( $query_default->have_posts() ) : $query_default->the_post();

        endwhile;

    else : // else; no posts
        _e( 'Nothing published so far.', TEXTDOMAIN_CONSTANT );
    endif; // endif; have_posts();

    wp_reset_query();
1

If you look at the Custom Fields page on WordPress codex, you can see the functions for Custom fields.

The "Template Tags" are the functions you generally use on your template:

  • get_post_custom() - Returns a multidimensional array with all custom fields of a particular post or page.
  • get_post_custom_values() - This function is useful if you wish to access a custom field that is not unique, i.e. has more than 1 value associated with it
  • get_post_custom_keys() - Returns an array containing the keys of all custom fields of a particular post or page.

Follow the links to each function to see examples on how to use them.

UPDATE: Ok, now I understand. You should try to add as many details as possible in your question for us to understand. As kaiser says, you should create a loopand add 'post_type' => 'custompost' to get the posts from that custom type. You can use the get_posts() function for this too.

1
  • i'm afraid you don't understand me... i have a custom post type called "custompost" and i want to display them on a wordpress page named "examplename"... how should i edit the page.php template to show the posts from "custompost" custom post type the same way as index.php shows normal posts?
    – m3tsys
    Commented Feb 10, 2011 at 17:18

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.