I am modifying a wordpress site that is for online lessons.

I am modifying the lesson template which originally had one navigation sidebar for a lesson.

I have added a vertical tab switcher so that I can display other things related to lessons (so I will have dynamic vertical tabs where user can choose syllabus, tasks, discussions in navigation bar) and in stepping through the code in PHPStorm with xdebug I noticed that there are a lot of calls to get_posts() made in various template part builders.

So you have this sort of structure:

Load lessons navigation menu
    Display basic lesson info
    Call a function to get topics and display topics
        Call another function to get topic quizzes

Now display main content

The thing is, a lot of the info I want to display in other navigation tabs (, say tasks, discussions) is info already extracted in previous function calls for building the syllabus navigation tree but which are not available to me after the function's return back to the main template.

Now, I can redo various function calls, but seems like such a waste.

How does one typically pass post data among the various scripts that are used to render a page so that you don't have to redo queries?

Above said, would something like angularjs be a better approach to dealing with post data and having it available to all the HTML elements that I deem necessary?

Just trying to figure out how you typically address this sort of data sharing across scripts without just declaring a bunch of globals (or is that valid way?)



  • I think you're looking for one of these: digwp.com/2011/09/3-ways-to-reset-the-wordpress-loop – Michelle Oct 21 at 18:34
  • The thing is there are so many files, each performing various queries, and to use those reset functions I would have to go through various scripts and figure out where/when I need such resets. Maybe globals make sense in this case or just adding onto some existing global the data that I need to retain. – Brian Oct 21 at 18:56
  • It's very hard to advise without seeing the code, but if you use your own custom WP_Query calls to handle the stuff in the tabs I'm not sure why you'd run into issues. You could cache those calls using the Transients API if you're concerned about performance? – Michelle Oct 22 at 15:22
  • Well, it is not only about performance. I just don't see why I need to redo a bunch of queries in one template parts file if a previous template parts file already fetched the needed data. Maybe it is just that I am using a plugin that has weird approach to rendering... – Brian Oct 23 at 6:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.