• I’m developing a plugin for a newsletter site.

    On the home page of this site is a display of all the Dates and Deadlines, News Articles, and Announcements custom post types that are current.

    Inside the plugin is a feature to grab all those current Dates and Deadlines, News Articles, and Announcements and compile them into a viewable preview showing what it would look like inside a specific Pardot email template.

    You’d think the biggest challenge here is negotiating Pardot’s API from within the plugin, but it’s not.

    The function the populates the front page is just a PHP template inside a custom theme in the site.

    The function that populates the Pardot preview is a similar function that runs from within the custom plugin I’m developing.

    The two queries return different results for some reason. Not different sets of articles, but the Pardot preview… it just shows one article (it’s correct, it should be shown, but there should be others as well)

    I even went so far as to take the entire page template from the theme and put the code into a shortcode in the plugin, but same result.

    I’m a little puzzled by this as in the case of my plugin shortcode vs. the theme template page code, it’s EXACTLY same code and query, running from two different places in the site (theme and a plugin) with different results.

    I can and am currently putting together a sample of the pages in question on the dev site and will provide links shortly.

    • This topic was modified 10 months, 2 weeks ago by brownbagmarketing. Reason: Clarification
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter brownbagmarketing

    (@brownbagmarketing)

    Well… what can I say but dev is dev…

    In setting up the dev site to provide example links, it all appears to be working in dev now… sigh.

    Leaving this open because I have it feeling it is not resolved. And any insight anybody might have as to why this is occurring in my local would be very welcome.

    Moderator bcworkz

    (@bcworkz)

    What’s different between your dev site and production site? Maybe same theme but different plugins?

    Any theme or plugin can conditionally alter posts queries. I suspect that’s what is happening. I suspect that if you deactivated all plugins you’d get the same behavior in both sites.

    Another way you could investigate is to echo out WP_Query::request property of each query object. Something will be different. What is different could indicate what plugin is responsible for altering the query.

    Another possibility is the Pardot preview arbitrarily shows only one post regardless of how many you send. Perhaps you should be examining the data being sent instead of the Pardot preview before deciding the query results are different.

    FWIW, the one significant difference between plugin and theme code is plugins load very early and the theme loads relatively late. But it shouldn’t matter since your queries are presumably run after WP has fully loaded.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Query behaves differently depending on where it runs from’ is closed to new replies.