Home > Uncategorized > Exec-PHP Not Displaying Categories or Archive List

Exec-PHP Not Displaying Categories or Archive List

March 8th, 2009

I’m currently in the process of converting one of my old sites from Moveable type to Wordpress. The site hasn’t been updated since 2007 and all the pages were static pages. I decided to port it over to wordpress and make it dynamic by getting offer information from a database.

I decided to store the offers in a database because in the past, I would get calls from the networks telling me that the wording on a page was incorrect and that I had to change it before a specific day or my affiliate link would be deactivated. This meant that I had to go to every page where the offer was listed and manually make the corrections on each page.

With the offers now stored in a database, I can just make changes in one place and the information will be automatically updated on all the pages where the offer is displayed.

Exec-PHP Plugin

With a standard installation of Wordpress, you are not allowed to include any php code in any of your posts or pages, unless you get sometype of plugin which will allow you to do so. I decided to go with the Exec-PHP plugin by Sören. There are other plugins out there that get the job done, I just settled on this one based on the number of downloads it had compaired to the others.

The plugin works great. I was able to query the mysql database and display the information within a wordpress post or page. The only problem was that when queried the database using php, my category list and archive list would become empty. I didn’t know exactly what was causing it or why. I checked everything that I could possibly check to find out what was causing this. I checked the code for the sidebar, checked my php code, checked the template code, nothing.

After scratching my head for hours, I finally figured out what was causing this. It was happening because the user name and password that I used to query my offers database was the same username/password that wordpress used to run the site.

Since my code was executed first, I was able to connect to the database and get the information that I needed and then close the connection. Once I closed the connection, wordpress no longer had a way to get the information about the categories and posts, so it displayed nothing.

The moral of the story is this:

If you use the exec-php plugin for wordpress to retrieve information from a database, make sure that you do not use the same database username that you’re using to run your wordpress site. Create a different user to use with the exec-php plugin.

Uncategorized , ,

  1. No comments yet.
  1. No trackbacks yet.