Testing for Values Passed in URL
-
I have a glossary page in which the a reader can click on a letter to see a list of posts that start with the selected letter.
The selection process works as expected but a member of the forum suggested checking for an occurence where a value was not passed.
My code for this is
<?php $letter = $_GET['letter']; if ($letter=="") echo "No Entries Found!"; else $loop = new WP_Query( array( 'post_type' => 'glossary', 'meta_key'=> 'first-letter', 'meta_value' => $letter, 'posts_per_page' => 10 ) ); ?>
This returns the expected text on the page if I artificially create a url without a value.
However, there is also an error message from WP, thus:
Fatal error: Call to a member function have_posts() on a non-object in /XXXXXXXXXXXXXX/wp-content/themes/twentyten/glossaryListLetter2v0.php on line 14
I’m looking for guidance on whether I can code this in such a way as to avoid the error message from WP.
Sidenote: I’m less than a novice in php.Thanks.
- The topic ‘Testing for Values Passed in URL’ is closed to new replies.