CodeIgniter Forums
wordpress data in codeigniter project - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: wordpress data in codeigniter project (/showthread.php?tid=67085)



wordpress data in codeigniter project - shakeelahmed.cfs - 01-13-2017

hey everyone ,
 
i have been given a task which i have to submit it by monday .

since i m a newbie i dont have much coding concepts in codeigniter so if guys wanna help me in completing this task just xtend a helping hand

task is i m having wordpress blog and codeigniter blog, i have to fetch posts from wordpress blog into codeigniter blog .so if anyone know please help me out here .
i have installes oauth2 and wp rest api v2 plugin in my wordpress blog and generated a client id and secret key till here its done after this wat i have to plz suggest me..i have got hthe code from github too


RE: wordpress data in codeigniter project - enlivenapp - 01-13-2017

If you're going to do it REST API style, take a look at Phil Sturgeon's REST client library.  

https://github.com/philsturgeon/codeigniter-restclient


RE: wordpress data in codeigniter project - skunkbad - 01-13-2017

All you need to do is query the WordPress tables for the blog data. I'm not going to do all of the work for you, because that wouldn't be fair if this is an assignment, but here is a start:


PHP Code:
<?php if( ! defined('BASEPATH') ) exit('No direct script access allowed');

class 
Wp_model extends CI_Model {

    public $table_prefix 'wp';

    /**
     * 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;
    }
    
    
// -----------------------------------------------------------------------





RE: wordpress data in codeigniter project - enlivenapp - 01-13-2017

(01-13-2017, 10:50 PM)skunkbad Wrote: All you need to do is query the WordPress tables for the blog data. I'm not going to do all of the work for you, because that wouldn't be fair if this is an assignment, but here is a start:

I initially thought the same but he didn't mention if he has access to the WP database.  That might be why he was doing the REST API, but since he mentioned the API I went that direction.

If both sites are on the same server and the assignment allows it you're entirely correct, and it's the easier way to go about it.


RE: wordpress data in codeigniter project - skunkbad - 01-13-2017

(01-13-2017, 11:01 PM)Ienlivenapp Wrote:
(01-13-2017, 10:50 PM)skunkbad Wrote: All you need to do is query the WordPress tables for the blog data. I'm not going to do all of the work for you, because that wouldn't be fair if this is an assignment, but here is a start:

I initially thought the same but he didn't mention if he has access to the WP database.  That might be why he was doing the REST API, but since he mentioned the API I went that direction.

If both sites are on the same server and the assignment allows it you're entirely correct, and it's the easier way to go about it.

If that's the case the best thing to do, considering that it appears there is access to both servers, would be to set up the WP server to allow remote MySQL connections from the CI server.


RE: wordpress data in codeigniter project - enlivenapp - 01-13-2017

(01-13-2017, 11:07 PM)skunkbad Wrote:
(01-13-2017, 11:01 PM)Ienlivenapp Wrote:
(01-13-2017, 10:50 PM)skunkbad Wrote: All you need to do is query the WordPress tables for the blog data. I'm not going to do all of the work for you, because that wouldn't be fair if this is an assignment, but here is a start:

I initially thought the same but he didn't mention if he has access to the WP database.  That might be why he was doing the REST API, but since he mentioned the API I went that direction.

If both sites are on the same server and the assignment allows it you're entirely correct, and it's the easier way to go about it.

If that's the case the best thing to do, considering that it appears there is access to both servers, would be to set up the WP server to allow remote MySQL connections from the CI server.

True, but whitelisting remote servers for MySQL access can be a slippery slope for (assumed) new folks and open the server to security  vulnerabilities if done incorrectly... but I digress...  I don't want to get this too off topic.

Hopefully he finds one of the two ways helpful.


RE: wordpress data in codeigniter project - shakeelahmed.cfs - 01-14-2017

(01-13-2017, 10:21 PM)enlivenapp Wrote: If you're going to do it REST API style, take a look at Phil Sturgeon's REST client library.  

https://github.com/philsturgeon/codeigniter-restclient

yeah both the blogs are on the same server and i dont know how to make remote  mysql access connections that u were talking about.

can i do it in this way like i know the database username and password of my wordpress blog so is there anything i can do it with this piece of information


RE: wordpress data in codeigniter project - shakeelahmed.cfs - 01-14-2017

(01-13-2017, 11:12 PM)enlivenapp Wrote:
(01-13-2017, 11:07 PM)skunkbad Wrote:
(01-13-2017, 11:01 PM)Ienlivenapp Wrote:
(01-13-2017, 10:50 PM)skunkbad Wrote: All you need to do is query the WordPress tables for the blog data. I'm not going to do all of the work for you, because that wouldn't be fair if this is an assignment, but here is a start:

I initially thought the same but he didn't mention if he has access to the WP database.  That might be why he was doing the REST API, but since he mentioned the API I went that direction.

If both sites are on the same server and the assignment allows it you're entirely correct, and it's the easier way to go about it.

If that's the case the best thing to do, considering that it appears there is access to both servers, would be to set up the WP server to allow remote MySQL connections from the CI server.

True, but whitelisting remote servers for MySQL access can be a slippery slope for (assumed) new folks and open the server to security  vulnerabilities if done incorrectly... but I digress...  I don't want to get this too off topic.

Hopefully he finds one of the two ways helpful.
yeah i am having wordpress database username and password , is there anything could be done with this. and i have just join this internship program so they are giving tasks which seems to be much tough to me


RE: wordpress data in codeigniter project - skunkbad - 01-14-2017

(01-14-2017, 12:24 AM)shakeelahmed.cfs Wrote:
(01-13-2017, 10:21 PM)enlivenapp Wrote: If you're going to do it REST API style, take a look at Phil Sturgeon's REST client library.  

https://github.com/philsturgeon/codeigniter-restclient

yeah both the blogs are on the same server and i dont know how to make remote  mysql access connections that u were talking about.

can i do it in this way like i know the database username and password of my wordpress blog so is there anything i can do it with this piece of information

Since both blogs are on the same server, you don't need a remote connection. You should just be able to make the connection from CI to the wordpress database. Simple to achieve just following the documentation in the user guide. I've already given you some code that should work instantly, and you'll need to find out the rest on your own. It's 1:15am here, and I've got to get to bed.