Home>Support>posts_per_page and offset not working in siteorigin page builder widgets

posts_per_page and offset not working in siteorigin page builder widgets

Hi there,

I found out that the query of the post loop widget in the siteorigin page builder does not take into consideration the posts_per_page and offset vars if you select the only sticky posts or exclude sticky posts from the UI.
This tested with Unwind theme (free).

Regards,
George

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 2 years, 8 months ago Alex S
    Hi, I Work Here

    Hi George,

    Can you please elaborate on the issue you’re facing? I’ve run some tests and the Posts Per Page setting and additional offset value is working as expected for me. while using SiteOrigin Unwind and Twenty-Twenty. Please note that the Posts Per Page setting is recommended over the adding posts_per_page to the additional field.

    For reference, here’s what each of the Sticky Posts options does:

    Default – Sticky posts are appended to search results and offset isn’t applied to Sticky Posts. This is the WordPress default.
    Ignore sticky – Don’t move the sticky posts to the front of the results, but will still allow for them to appear.
    Exclude – Exclude all sticky posts from post loop.
    Only Sticky – Only display sticky posts.

    Kind regards,
    Alex

  2. 2 years, 8 months ago gkorakas

    Hi Alex,

    I tried to use the Posts Per Page setting in the first place together with the Only Sticky setting and this is not working. All the above are tested in a new clean WP installation using the Unwind theme and the siteorigin Page builder plugin with the post loop widget. Inside post loop I have used the post slider template with Only sticky and another post loop with the Blog grid template.

    George

  3. 2 years, 8 months ago Alex S
    Hi, I Work Here

    Hi George,

    I’m having trouble replicating this result. Can you please clarify what value you set Posts Per Page to? Ideally, can you please provide me with a screenshot of your settings? You can upload the screenshot to Imgur or vgy.me. WordPress is designed to disregard the offset if the Posts Per Page setting is set to -1. There are also other situations where WordPress will intentionally disregard your selections if other settings prevent them from working as intended – these limitations typically can’t be avoided. Inspecting your adjusted setting values will allow me to identify if the results you’re getting are expected.

    Kind regards,
    Alex

  4. 2 years, 8 months ago gkorakas

    Hi Alex,

    I set Posts Per Page to be 1 and I check the Only Sticky option. Please find screenshot with settings and the posts I use.

    https://i.vgy.me/VDSt8Z.png
    https://i.vgy.me/UT3ljn.png

    Waiting for you reply.
    Regards,
    George

  5. 2 years, 8 months ago gkorakas

    I have tested the

    $GLOBALS['wp_query']->request

    after

    query_posts

    has run inside inc/widgets/post-loop.php of the panels plugin and I get the following query:

    SELECT SQL_CALC_FOUND_ROWS testwp_posts.ID
    FROM testwp_posts
    WHERE 1 = 1
    AND testwp_posts.ID IN (8, 10)
    AND testwp_posts.post_type = ‘post’
    AND (testwp_posts.post_status = ‘publish’ OR testwp_posts.post_status = ‘private’)
    ORDER BY testwp_posts.post_date DESC
    LIMIT 0, 1

    and this is correct as the SQL gives only 1 result.

    I still cannont find who mess with query after that.

  6. 2 years, 8 months ago Alex S
    Hi, I Work Here

    Hi Gkorakas,

    Thank you for the screenshot of your settings and posts. Does the expected number of replies show if you use a different template?

    Kind regards,
    Alex

  7. 2 years, 8 months ago gkorakas

    Hi Alex,

    The same happens with all the templates. Can you replicate the issue or it is working fine on your end?

    Regards,
    George

  8. 2 years, 8 months ago Alex S
    Hi, I Work Here

    Hi George,

    Yes. When I use the Post Loop widget using your settings and SiteOrigin Unwind, it works as expected – a single post per page and only the sticky posts. If I set an offset, the first sticky item is skipped over. If that’s the result you’re getting, but that’s undesired, can you please elaborate on your desired result?

    If you’re not getting that result, and that’s what you would like to see, can you try disabling all non-SiteOrigin plugins and see if this fixes the issue? You’ll need to clear all your caches after disabling your plugins.

    If it does fix the issue, then try re-enabling your plugins one by one until the issue comes back. This procedure will help diagnose which plugin is causing the issue.

    Once we know that, we’ll be able to look at what might be causing the conflict and either solve the problem or help you find an alternative plugin.

    Kind regards,
    Alex

  9. 2 years, 8 months ago gkorakas

    Hi Alex,

    I am not using any other plugins. I am testing on a new clean WP installation with Unwind theme and site origin page builder plugin.

    I will dubug this further and I will come back to you.

    Regards,
    George

  10. 2 years, 7 months ago gkorakas

    Can I use pre_get_posts hook to change the query for a specific page builder widget in a page? Can I determine which query has to do with a specific widget?

    I am trying to build a page that will show only sticky posts but with a limit (like 10 posts) so as the sticky posts inscrease in the site the page will always show the last 10 sticky posts.

    Regards,
    George

  11. 2 years, 7 months ago Alex S
    Hi, I Work Here

    Hi Gkorakas,

    In theory, yes.a

    Can I determine which query has to do with a specific widget?

    You’ll need to pass an additional parameter to identify the post loop – for example, add test=123 and then check for the test additional parameter.

    I am trying to build a page that will show only sticky posts but with a limit (like 10 posts) so as the sticky posts increase in the site the page will always show the last 10 sticky posts.

    Ah. Thank you for clarifying. All (bar the Slider) Unwind post loops templates are designed to allow for pagination so upon posts_per_page amount is reached, a new page will be linked. There’s no direct way to disable the pagination, but you could hide the pagination using CSS.

    Kind regards,
    Alex

  12. 2 years, 7 months ago gkorakas

    Hi Alex,

    I am afraid that the paginations is not working with sticky posts.

    Regards,
    George

  13. 2 years, 7 months ago gkorakas

    Something is messing with the query sto the following code does not work either.

    add_filter('post_limits', function ($limit, $query) {
        $param = $query->get('test123') === '1' ?? false;
        if ($query->get('post_type') !== 'post' || ! $param) {
            return $limit;
        }
        return 'LIMIT 0, 1';
    }, 10, 2);
    
  14. 2 years, 7 months ago gkorakas

    Please also look into the following. The post__in is indeed an array of 5. This should be enough to limit the WP query.

    ["post__in"]=> array(5) { [0]=> int(449) [1]=> int(443) [2]=> int(746) [3]=> int(893) [4]=> int(1317) }
  15. 2 years, 7 months ago Alex S
    Hi, I Work Here

    Hi Gkorakas,

    The provided PHP requires the additional field to be set to test123=1. Upon setting the additional field to that the provided PHP is working as expected for me. I tested this by adding the provided snippet using the Code Snippets plugin.

    Kind regards,
    Alex

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More