• hello every body ??
    hop to have a good day ??

    my friends I have a site based on wordpress that I get author id and post id by following codes :

    [ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]

    <?php
    echo (the_author_meta('ID') ); //author id
    
    echo (get_post_field('ID', $post_id)) ;//post id
    ?>

    now I want save this details in other data base but I cant ??

    who know true Answer??

    … by the way I must say that when I insert my data in new db null result fill in that ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • Do you just need those fields in another database or are you trying to replicate a WP table entirely?

    Thread Starter ncsm

    (@ncsm)

    see
    i want get this details and save them on my new DB and I dont want to do anything on Wp databases or have similar data base like that

    i just want those 2 details ‘

    Very simple normal PHP way to go about it

    define('dbhost','YOUR HOST e.g. localhost');
    define('dbname','YOUR DB NAME');
    define('dbuser','YOUR DB USERNAME');
    define('dbpass','YOUR DB PASS');
    
    $dbconn = new mysqli(dbhost, dbuser, dbpass, dbname);
    
    $mid = get_the_author_meta('ID', ID OF USER);
    $pid = get_post_field('ID', ID OF POST);
    
    $dbconn->query("INSERT INTO YOUR TABLE (YOUR FIELD FOR META ID,YOUR FIELD FOR POST ID) VALUES ('.$mid.','.$pid.';");

    You need a while loop to go over each and a way to get the user and post id you want.

    Not used a prepared query as your php version might not support it, might wanna do some int validation to avoid the very unlikely sql injection.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘save wordpres information in new database (using wp shortcodes)’ is closed to new replies.