• I have been following this page and coded get_post()

    http://codex.wordpress.org/Template_Tags/get_posts

    $args = array(
    	'posts_per_page'  => 15,
    	'numberposts'     => 15,
    	'offset'          => 0,
    	'category'        => '',
    	'orderby'         => 'id',
    	'order'           => 'DESC',
    	'include'         => '',
    	'exclude'         => '',
    	'meta_key'        => '',
    	'meta_value'      => '',
    	'post_type'       => 'custom-post-type',
    	'post_mime_type'  => '',
    	'post_parent'     => '',
    	'post_status'     => 'publish',
    	'suppress_filters' => true );
    
    $myposts = get_posts( $args );
    
    foreach( $myposts as $post ) : setup_postdata($post); ?>
    
    <li>(<?php the_ID(); ?>)
    		<?php the_date(); ?>
              <a>"><?php the_title(); ?></a>
      		<?php the_excerpt(); ?>
    
    </li>
    <?php endforeach; ?>

    this is “custom post type” single pages. and I want to create relative posts bottom of this single pages. but except the_excerpt(), it displays the current page information. all same result values, except excerpt.

    any solution? I am not supposed to use the post() on single pages?

    actually, I am trying to get category = 11 posts only. but if I do “category=11”, then nothing shows.

    any tips?

Viewing 1 replies (of 1 total)
  • BenRacicot

    (@benracicot)

    Hey there, I do think that things get complicated with get_posts. You need to make the $post variable global! Very important.

    I was having trouble getting the_title to work within the same setup as yours above until I went over this -> http://wordpress.stackexchange.com/questions/9834/setup-postdata-does-not-seem-to-be-working

    As for your category issue:
    cat argument takes an integer. (in this case excluding category 20)

    'cat' => -20

    Supposedly category_name takes a string but I’ve had trouble with it:
    'category_name' => 'design'

Viewing 1 replies (of 1 total)
  • The topic ‘get_posts() problem..the_title() is not showing.’ is closed to new replies.