farhad.a
farhad.a

Reputation: 341

get the id of custom post type in single page

I have a custom post type in my wordpress template named downloads.

The problem is I can't get the id of post with this type in single page using these codes

global $post;
echo $post->ID;

But I can get the id of posts with type page or post with that lines.

How can i do that?

Thank you

Upvotes: 1

Views: 5933

Answers (2)

Samyappa
Samyappa

Reputation: 531

$args = array( 'post_type' => 'portfolio');

$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
    the_ID();
endwhile;

Upvotes: 0

farhad.a
farhad.a

Reputation: 341

Finally I found the answer of my question.

When I register post type with register_post_type() method I should use flush_rewrite_rules() to recreate url rewrites rules after that.

This problem occured because the url rewrite rules cause I can't get post content and so post id in single.php page.

Upvotes: 1

Related Questions