0

thanks to help provided by this forum, I have managed to develop a plugin that uses a database of UK towns & postcodes - using the URL parameters to build up a query & display the results. I'm at the stage now where I need to format the page - and this is where things aren't working as expected.

Lets say I click on a link for "england" - this queries the DB for all the counties / states in the UK. Extract from the Filter / plugin looks like the following:


$content = get_the_content();
$test = fs_query(get_query_var('delivery_country'));
//$content = 'Delivery location is ' . get_query_var('delivery_country');
//$content = str_replace( 'XXXXXXXXXX', fs_query(get_query_var( 'delivery_country')), $content );
//$content = str_replace( 'YYYYYYYYYY', get_query_var( 'delivery_country' ), $content );
$content .= $test;
return $content;

The function and the query work - lets say url was xyz.com\delivery\england then the plugin queries the DB for all counties in england. The results from the query are stored in the variable $test. What I am trying to do - as you can see from the various statements is modify the content of the page with the values in "$test".

No matter what I do, the values in $test appear first. Ideally, I want the contents of $test to appear in the middle of the page (where XXXXXXXXXX is located)?

Is there something I need to do that I am missing

Many thanks in advance....

  • I'm not familiar with fs_query, where is it implemented? It's not a Core WP function – Tom J Nowell May 6 at 12:41
  • Hi - fs_query is a function within my plugin to query the database..... – Fozzy279 May 6 at 12:56
  • Can you share it? Also, where is the code in your question appearing? It looks like it's inside a function but there are no clues as to what the function is, where it appears, or how its called. Also can you provide some information about the post itself? Is this a page? A CPT? Is there a particular reason this isn't a block or a shortcode? – Tom J Nowell May 6 at 13:15
  • Normally when some data appears before everything else, it's because the code is echoing it. As Tom noted you'd need to provide more of the code for more specific assistance. – WebElaine May 6 at 13:20
  • Hi ... After a bit of investiation - you are right - my function to display the query results was "echoing" the output there... I modified the function to return the string, rather than echo it, and it is now displaying in the correct place.... Thank you all for your help... easy when you know how!! :-) – Fozzy279 May 6 at 13:29

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.