CyberShot Posted April 9, 2011 Share Posted April 9, 2011 I am working with wordpress. I am using a chunk of code to get the category id's of 2 categories. when I do that, it outputs 1 and 5 which is correct. I then use that to change the query for the database so that it will exclude those categories. But for some reason the code is failing. I can't see why. Is there a way to see what php is generating? Like when you click view source from a web page. Is there a view source for php? This is the code //getting the option tree results $options = get_option('option_tree'); //looping through my key to get the values, this returns 1 and 5 foreach($options['exc_cat'] as $cat) { //concatenating my values into one string. I want the string to be -1,-5 $string .= '-' .$cat.","; } //trimming the trailing comma from the string, otherwise I would end up with -1,-5, $string = substr($string, 0, -1); // Delete the last character query_posts($query_string . '&cat=' . $string); //this is the line that I need to see exactly what it is sending to the database. Quote Link to comment https://forums.phpfreaks.com/topic/233172-how-to-view-php-output/ Share on other sites More sharing options...
trq Posted April 9, 2011 Share Posted April 9, 2011 Is there a view source for php? Your editing the code, what exactly do you want to view? Quote Link to comment https://forums.phpfreaks.com/topic/233172-how-to-view-php-output/#findComment-1199123 Share on other sites More sharing options...
CyberShot Posted April 9, 2011 Author Share Posted April 9, 2011 The code should put out something like this query_posts($query_string . '&cat=-1,-5'); the line above should be making 5 posts I have on my page disappear, but they are still there. I have gone through the codex for two days now and everything in the documentation says that my code above should work. So I am thinking now that there is a missing ' at the end of the string. But I can't seem to make it work. So I thought that there was a way to view the output. I am trying to echo it right now to see but it looks good. I get -1,-5. I just need to make sure that the quotes are right and I can't see that. Quote Link to comment https://forums.phpfreaks.com/topic/233172-how-to-view-php-output/#findComment-1199125 Share on other sites More sharing options...
trq Posted April 9, 2011 Share Posted April 9, 2011 If you track down the query_posts() function you could echo the argument within there. Quote Link to comment https://forums.phpfreaks.com/topic/233172-how-to-view-php-output/#findComment-1199140 Share on other sites More sharing options...
CyberShot Posted April 9, 2011 Author Share Posted April 9, 2011 I got it figure out. I think there was a problem somewhere further down in my code. When i replaced the file with an unedited version and then added in my code snippet, it worked. How do you mark a thread solved? Quote Link to comment https://forums.phpfreaks.com/topic/233172-how-to-view-php-output/#findComment-1199145 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.