My situation and my problem:

I have about 200 pages of a custom post type on my website. A user can click a button that reads "Add to my List" on each page which adds a custom taxonomy term to the post that corresponds to the users ID (Taxonomy A). All of that works fine.

Then I have a "My List" page that displays the list of pages that the user created. To do this, I run a bunch of tax queries for the users ID. Since every page of this custom post type also has a second taxonomy with its own terms that I want to separate the pages by, I also include a second taxonomy to each query (Taxonomy B). Then I display the list of the pages that have the userID-term of Taxonomy A. To make everything more organized, I divide this list into a few sections by using the terms of Taxonomy B. Displaying the list works fine too.

Now I want to create a page that shows the user some statistics about how many pages of each term from Taxonomy B his list includes. My approach was to set up a $termCount variable for each Taxonomy B term and increment that number by one every time that the "My List"-Page loops through one of the posts with the respective term.

Now If I wanted to display the statistics on the "My List" page, that would be no problem since all my $termCount variables are right there. However, I want to create a separate page for the statistics but I can not figure out how to pass along the $termCount variables to the new page. Note that these are user specific and may change every time a user adds or removes a page to/from his list.

I already tried to set up a new php file that loops through the posts returned by my initial query and increment the term count for each post and then require that page on my statistics page but that resulted in the page not loading at all. It looked something like this:


require get_theme_file_path('/inc/list-query.php');

$termCount1 = 0;    $termCount2 = 0;    $termCount3 = 0;    




And then I would require this file within the page that contains my Statistics HTML in order to work with the $termCount variables.

Is there a different or perhaps an easier way to pass along dynamic and user specific variables between PHP files?

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.