• I am currently building an internal one-page quote form that will need data from a WordPress website. It will require different ACF fields for each product from a custom post type. The website have to be on different servers so I can’t just require wp-blog-header.php from the quote form. Is there anything I can do to connect to wp-blog-header.php so I can use ACF functions to call the custom fields or if not is there a neater way to output the ACF fields data?

    This is what I currently have for the meta data data.

                SELECT wp_posts.ID, wp_posts.post_title, wp_posts.post_name, wp_postmeta.meta_key, wp_postmeta.meta_value
                FROM wp_posts, wp_postmeta, wp_term_relationships
                WHERE wp_posts.post_type =  "products"
                AND wp_posts.post_status =  "publish"
                AND wp_posts.ID = wp_postmeta.post_id
                AND wp_postmeta.post_id = wp_term_relationships.object_id
            ';
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Directly requesting most WP files (there are limited exceptions) will rarely end well, don’t bother even trying :). In theory you could directly connect to the DB server, but most commercial hosting DB servers have referrer whitelists. There are very good chances your sever is not on the whitelist, so in practice this is not a viable option.

    Your best option normally is to get the desired data through the REST API. ACF fields are stored in various object meta tables. The specific values returned need to be specifically exposed to the API to be accessible. I’m not sure if ACF fields are or not. It could be ACF even provides its own routes through the API. Check their docs to see if this is an option.

    If you’re able to add custom code to the WP site, you could instead install a custom PHP handler to fetch the data you want. To access such a handler, if you are requesting via JavaScript, make an Ajax request through /wp-admin/admin-ajax.php. Otherwise request through /wp-admin/admin-post.php. With custom code like this you can use the usual ACF functions to access data.

    Thread Starter luciddigital1

    (@luciddigital1)

    Thanks bcworkz,

    Your reply was much appreciated.

    We’ve ended connecting to the database through a SQLI query through a class and created functions that output different parts of the database. it doesn’t have to be dynamic so the fields we needed could be hardcoded.

    Thanks for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Connecting to WordPress database using mysqli from another server with wp-blog-h’ is closed to new replies.