Closed tuonela closed 9 years ago
Never mind. I figured it out! For anyone else looking for the answer to this:
I made a controller specifically for handling wordpress pages. In the controller, I made an index function that looks like this:
public function index() {
$pageurl = current_url();
global $wpdb;
$page = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $pageurl));
return $page[0];
}
Then, in my routes file I did this:
$route['404_override'] = 'wppage';
where 'wppage' is the name of my controller.
I hope this helps others!
Thanks! I actually have an improved version of the WordPressIgniter plugin that I need to get around to pushing to github that uses shortcodes as well, much better than the current route grabber.
-- update: The latest version here on github does use shortcodes.
I did this:
$route['404_override'] = 'main/catchall';
And in main.php, the function simply echos "That's a CodeIgniter 404". In my case, I didn't need to look up any WordPress posts in the database. If there was a post that matched the url, WordPress should be displaying it anyways, and the CodeIgniter output would not be shown.
Oh, one thing I always assume, which may not be correct in your case: SEO urls + apache rewrite. I really can't say what would happen if the url-parameter methods were used to identify pages and posts, along with the CodeIgniter plugin. CodeIgniter is intended to use the url segments, and WordPress can (should I say, SHOULD) be using SEO urls as well. I really have not tested my plugin without everything 100% SEO urls, so your luck may vary, in that regard.
My scenario is this: We have built an application for searching and displaying results with regards to property listings from an MLS system. We built this application in CodeIgniter. People can perform a search, which then displays a page of results, then they can click on a result to see more details. There are three different controllers, models, and views for these actions. We needed to integrate this application into a WordPress site that also uses native WP pages and posts that are not related to the CodeIgniter application. (e.g. "About Us") So, CodeIgniter does not handle all page requests, nor should it return a 404 error for native WP pages. In order for the calls to different CodeIgniter controllers and views to work, in the plugin settings, we had to check the "Divert 404s to WordPressIgniter" box, and the "CodeIgniter grabs all SEO urls" box. We have our CodeIgniter server path configured, and we also checked the box for "Trigger with [wordpressigniter] shortcode in posts, too.". That's it for our settings. Then I integrated the code I mentioned above to force CodeIgniter to display the native WordPress page (e.g. "About Us") by directing the CodeIgniter 404 route to look at a controller which recognizes the WP page that is being called and returns the page. Simple!
In any case, this plugin works perfectly with the settings I described in our scenario. Thank you for such an excellent, easy to install and configure plugin for this integration!
Can you provide an example of how to set "$route['404_override']" so that WordPress pages will display when "CodeIgniter grabs all SEO urls" is checked in the plugin settings? Also, an example of the controller used in "$route['404_override']"?