Welcome Guest, Not a member yet? Register   Sign In
Wordpress integration
#1

Hi,

i've searched, but i find only similar posts that don't solve my problem.

I've a website in Codeigniter. Now, i want to add some page made with wordpress, for example a homepage and a contact page (i'd like to use wordpress because these pages will be make by my collegues that know perfectly wordpress).
How can i have some page in CI and others in WP ? 

For example, i need:

http://mysitename.com => show WP homepage
http://mysitename.com/animals/cat => call "cat" function of "animals" controller in CI
http://mysitename.com/contact => show WP contact page

I tried to follow this guide: https://www.cometchat.com/blog/how-to-in...wordpress/

But this didn't resolve the problem. Infact, to show WP homepage i've to go in the WP subdirectory.. something like: http://mysitename.com/wordpress and i want avoid to show subdirectory in url.

Thank you in advace and sorry if my english is not so good
Reply
#2

I've tried a few ways to merge the two applications in the past. My opinion is that the best way to handle the merge is just to use mod_rewrite in an .htaccess file to "pre-route" to each application. Whichever application would handle more requests is the default, and for the other application you simply rewrite to a different front controller. So if you're WordPress app uses index.php, then the CI app uses ci_index.php.
Reply
#3

Hi, thank you for the answer
To do this, should i have wordpress and codeigniter in the same directory? because the .htaccess redirect changes the url and the only way to avoid this is to have all in the same directory
Reply
#4

Yes. If you look at WP it has wp-content, wp-admin, wp-includes, while CI has application, system. That being the case, there's really no reason why these two apps can't live together in the same directory.
Reply
#5

I will try this solution, thank you a lot! Smile
Reply
#6

One thing you can try is using the WordPress REST API. This allows you get WordPress REST API data objects that can be interfaced with other applications.

So, you can pull your homepage data via WordPress REST API and display on your codeigniter home page.. You can also do this with other Pagea as well..

When loading your view pass the WP JSON object and render inside your codeigniter view page.


Here is a link to the WordPress REST API
Reply
#7

(02-09-2018, 03:30 PM)gabrielcastillo Wrote: One thing you can try is using the WordPress REST API. This allows you get WordPress REST API data objects that can be interfaced with other applications.

So, you can pull your homepage data via WordPress REST API and display on your codeigniter home page.. You can also do this with other Pagea as well..

When loading your view pass the WP JSON object and render inside your codeigniter view page.


Here is a link to the WordPress REST API

That's kind of an awkward way to get data, when you have full access to the database. Why not just use CI to query the WP database directly? I do it all the time. Example method:

PHP Code:
/**
 * Get all posts.
 *
 * No revisions or drafts are allowed
 *
 * You have to join the posts table with the term relationships table
 * in order to get the term taxonomy ID. Then you have to join the 
 * terms table because the term taxonomy ID is the term ID, which gives
 * you the slug and category name for the post.
 */
public function get_all$selections NULL )
{
    if( empty( 
$selections ) )
    {
        
$selections '*';
    }

    
$query $this->db->select$selections )
        ->
from$this->table_prefix '_posts p' )
        ->
join$this->table_prefix '_term_relationships tr''p.id = tr.object_id''left' )
        ->
join$this->table_prefix '_terms t''tr.term_taxonomy_id = t.term_id''left' )
        ->
where'p.post_type''post' )
        ->
where'p.post_status''publish' )
        ->
order_by'post_date''desc' )
        ->
get();

    if( 
$query->num_rows() > )
    {
        return 
$query->result();
    }

    return 
FALSE;

Reply
#8

(02-09-2018, 06:04 PM)skunkbad Wrote:
(02-09-2018, 03:30 PM)gabrielcastillo Wrote: One thing you can try is using the WordPress REST API. This allows you get WordPress REST API data objects that can be interfaced with other applications.

So, you can pull your homepage data via WordPress REST API and display on your codeigniter home page.. You can also do this with other Pagea as well..

When loading your view pass the WP JSON object and render inside your codeigniter view page.


Here is a link to the WordPress REST API

That's kind of an awkward way to get data, when you have full access to the database. Why not just use CI to query the WP database directly? I do it all the time. Example method:

PHP Code:
/**
 * Get all posts.
 *
 * No revisions or drafts are allowed
 *
 * You have to join the posts table with the term relationships table
 * in order to get the term taxonomy ID. Then you have to join the 
 * terms table because the term taxonomy ID is the term ID, which gives
 * you the slug and category name for the post.
 */
public function get_all$selections NULL )
{
    if( empty( 
$selections ) )
    {
        
$selections '*';
    }

    
$query $this->db->select$selections )
        ->
from$this->table_prefix '_posts p' )
        ->
join$this->table_prefix '_term_relationships tr''p.id = tr.object_id''left' )
        ->
join$this->table_prefix '_terms t''tr.term_taxonomy_id = t.term_id''left' )
        ->
where'p.post_type''post' )
        ->
where'p.post_status''publish' )
        ->
order_by'post_date''desc' )
        ->
get();

    if( 
$query->num_rows() > )
    {
        return 
$query->result();
    }

    return 
FALSE;




Of course that will work.. But to keep things simple, you could use
Code:
/wp-json/wp/v2/pages?slug=home-page

to get all the data into your view template and parse the object however you want. No need to create another model if not needed. My example is just a quick solution to the problem above.
Reply
#9

Your Wordpress level is very high. Good job!!! Thanks!!!
Programador Web - Consultor SEO - antonioalcala.com
Reply
#10

Hi sir, I would like to ask about the integrating thing using wp-json, should the wp and CI database should be one or can be done seperately? I am new and I run a site with CI script and love to create a posts using wp.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB