custom query args not working

Support MB Views custom query args not working

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #42290
    Ole PoetterOle Poetter
    Participant

    Hi,

    actually an easy task: I would build a archive for a cpt in views.

    I use a custom query, but the args post_per_page, orderby and order does'nt take affect.

    Here is my view:

    <div class="pbgrid">
    {% set args = { post_type: 'mycpt', posts_per_page: 5, orderby: 'title', order: 'ASC' } %}
    {% set posts = mb.get_posts( args ) %}
    {% for post in query.posts %}
    <img src="{{ post.thumbnail.thumbnail.url }}" width="{{ post.thumbnail.thumbnail.width }}" height="{{ post.thumbnail.thumbnail.height }}" alt="{{ post.thumbnail.thumbnail.alt }}">
    {{ post.title }}<br>
    {% endfor %}
    </div>

    Curiously, if I change the post_per_page, orderby and order args, I can see the change if I debug the quere with Query Monitor Plugin. But the content on the archive page is always ingoring the args.

    Any Idea?

    Kind regards,
    Ole

    #42298
    PeterPeter
    Moderator

    Hello Ole,

    The custom args doesn't work because you are using the default args of the main query:

    {% for post in query.posts %}

    you should change it to

    {% for post in posts %}

    to use the custom args.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.