I'm having an issue with the order WordPress is loading page templates and functions.php.
I have front-page.php which has $_POST['sort-by'] allowing users to sort posts using a drop-down menu.
It's simple enough and works just fine. Now comes the part where I have the ability to "Load more posts" which uses wp_ajax and wp_ajax_nopriv and a function in functions.php to grab the additional posts with an offset of the number of posts shown by default. My AJAX query works just fine, but I'm unable to grab the $_POST data from the front-page.php template within' functions.php to properly sort the posts fetched by the AJAX.
I thought it'd be as simple as just including my same $_POST values within' functions.php so it would use the proper sorting+meta_key, but no matter what I do including attempting to assign a separate variable to $GLOBALS containing the $_POST, I can not for the life of me get it to get the values set in front-page.php in functions.php so it will sort it properly when calling wp_ajax and wp_ajax_nopriv.
I'm assuming this has to do with functions.php being loaded BEFORE front-page.php within' WordPress. I'm not sure if there's an add_action(); of some kind that would allow me to fix my issue here or how I should go about getting it to work as intended. I know it has to be possible though.
EDIT: Here is the function I'm trying to get $_POST data for from my page template frontpage.php
$_POSTdata to fetch within' my AJAX request then? I tried setting it to a new variable and then globaling that variable with no avail. Pretty stuck on how to accomplish this as I need these posts to sort properly so my AJAX request doesn't pull duplicate posts.wp_ajaxactionin your javascript.$_POSTthough. I'm just calling thatget_reviews()function as seen above which passes the arguments in the$argsarray towp_queryand then shows the necessary posts. But, sincefront-page.phpis actually fetching the$_POSTvariables from the dropdown, it's sorting them differently then what is being done inget_reviews()thus the ajax called posts are not in the proper order. The ajax its self works just fine. If I'm just misunderstanding what you're saying, could I get an example? This has to be possible some way or another.