Skip to content
themeforge
EN
Start free
Menu
  1. Home
  2. Attribute reference
  3. wp-query
Core Blog and posts

Show the latest posts on any page

wp-query="'post_type'=>'post','posts_per_page'=>3"

News on the home page, three articles under a post, upcoming events: the block fills itself from WordPress, and the client only publishes posts.

Where it goes

On the block that holds the cards. The value is the WordPress query settings as pairs: 'post_type'=>'post','posts_per_page'=>3. The query-string form post_type=post&posts_per_page=3 works too.

The first card is the pattern: put wp="post-title", wp="post-image", wp="post-date" and other post values inside it. The other cards in the markup are dropped.

A block with wp="no-results" right after it is shown when there are no posts.

Example: news on the home page

Markup index.html
<div class="news" wp-query="'post_type'=>'post','posts_per_page'=>3">
  <article class="news-card">
    <img src="images/news.jpg" alt="" wp="post-image">
    <h3><a href="#" wp="post-title-link">New autumn menu</a></h3>
    <p wp="post-date">October 1</p>
  </article>
</div>
<div class="news-empty" wp="no-results">No news yet</div>
In the admin Posts
Posts
  • New autumn menu
  • Filter of the day is back
  • Open on Sundays
  • Pastry week
On the site the home page
News
New autumn menu Oct 1
Filter of the day is back Sep 20
Open on Sundays Sep 5

What matters

  • Settings in the WordPress format: post_type (post, product, your own type), posts_per_page, category_name, orderby.
  • A query the client should change without the markup: create it in ThemeForge → Queries and refer to it by name, wp-query="[latest-news]".
  • Page numbers under this list: wp-paginate-query on a block after it, see wp-paginate.

Common mistakes

The build log is the “Logs” tab of your project on themeforge.pro; the free markup check shows the same notes.

Not like this
<div wp-query="post|3">…</div>

A shorthand of your own: WordPress does not understand it and shows the latest posts. The build log names the value.

Like this
<div wp-query="'post_type'=>'post','posts_per_page'=>3">…</div>

Pairs in the WordPress format.

Alternative spelling

wp_query works the same: the build gives an identical theme.

Used in recipes

Ready when you are

See your site’s WordPress admin before you pay.