• Resolved Studioviv

    (@studioviv)


    Hello,

    I have a site with Advanced Custom Fields PRO and use a post object field to find the correct tables. Only I get the post ID and not the table ID. Is there a way to get the table ID with the post ID? Or can I programmatically auto change the table ID to the post ID?

    Let me know.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    The table ID to post ID mapping is stored in the tablepress_tables option in the wp_options database table. You could retrieve that array and then find the table ID for a given post ID.

    You can also change the table ID to something else (like a post ID), but I’m not aware of a way to do that automatically.

    Regards,
    Tobias

    Thread Starter Studioviv

    (@studioviv)

    Hello Tobias,

    Thank you for replying. I get the following string with the WordPress function get_option(‘tablepress_tables’):
    {“last_id”:18,”table_post”:{“1″:241,”2″:242,”3″:243,”4″:244,”5″:245,”6″:246,”7″:247,”8″:248,”9″:249,”10″:250,”11″:251,”12″:252,”13″:253,”14″:254,”15″:255,”16″:256,”17″:257,”18”:258}}

    How can I convert this to a PHP array? Or do I need another function to get those values?

    I tried the PHP unserialize() function. But without success.

    Please let me know.

    • This reply was modified 1 year ago by Studioviv.
    • This reply was modified 1 year ago by Studioviv.
    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    this is JSON, so this should do it:

    $option_value = get_option( 'tablepress_tables' );
    $tables = (array) json_decode( $option_value, true );
    $tables = $tables['table_post'];

    Regards,
    Tobias

    Thread Starter Studioviv

    (@studioviv)

    Hello Tobias,

    This is working perfectly. Thank you for all your help.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! 🙂 Good to hear that this helped!

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Get table ID with post ID’ is closed to new replies.