Support » Developing with WordPress » Output post in certain position

  • brveljkovic

    (@brveljkovic)


    I have custom post types. Is there a way to output a post which is in certain position. For example to output post which is in third position?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Hello brveljkovic,

    Do you mean get a post for output that is in the third position position on the default CPT archive list, so the third from newest custom post? Using the WP_Query class, instantiate a new query object using the same parameters as whatever query generates the list. For a CPT archive, only ‘post_type’ varies from default. To this argument, add ‘offset’ and ‘posts_per_page’ arguments. To get the third post, use ['post_type'=>'my_CPT', offset'=> 2, 'posts_per_page'=> 1,] for arguments.

    Do the usual custom query loop code to output the returned post.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.