dalenguyen / firebase-wordpress-plugin

A plugin that helps to integrate Firebase to WordPress
https://firebase-wordpress-docs.readthedocs.io
GNU General Public License v2.0
110 stars 31 forks source link

Post sync doesnt bring any meta data #167

Closed mmw562 closed 3 years ago

mmw562 commented 3 years ago

Hello Dale!

I was super excited about the feature to bring in the post data - its EXACTLY what I needed. The post did sync, but unfortunately, NONE of the post meta came with it - which was everything I needed. Is this something I'm doing wrong?

As an addition note, so much information came across that I didn't need. Is there any way to exclude certain fields?

dalenguyen commented 3 years ago

Hi @mmw562, getting post meta is possible. How your post meta is configured or created? You can attach a snapshot if you have any.

For general purposes, the post is synced with all data.

One way to save post meta / or exclude certain fields is to use the plugin's filter hook.

https://firebase-wordpress-docs.readthedocs.io/en/latest/hooks/filters.html

Together with save_post hook from WordPress (https://developer.wordpress.org/reference/hooks/save_post/).

mmw562 commented 3 years ago

The post is created using a form. The form software is called formidable. I have attached an image of how it is entered. The form itself creates a post and saves the meta data as I dictate in the form settings.

Screen Shot 2021-06-16 at 4 19 08 PM
dalenguyen commented 3 years ago

For custom metadata fields, you may need to do the following as I mentioned above. Do you have a developer that can help with it?

mmw562 commented 3 years ago

I may be able to handle this. Do you, by chance, have an example or docs for this filter? Specifically, the $doc_id is confusing to me. What is that referring to? Is it the post id?

dalenguyen commented 3 years ago

It's a term in firestore for document id.

/**
* Send Data to Firebase Database
*
* @param [type] $database_type realtime | firestore
* @param [type] $collection_name
* @param [type] $doc_id
* @param [type] $data object
* @return boolean
*/

// start saving data to firebase
apply_filters('firebase_save_data_to_database', $database_type, $collection_name, $doc_id, $data);

Example if you have $collection_name = 'users', and the $doc_id = '1', then your data will be saved to realtime / firestore under the path /users/1.

Hope this helps.

mmw562 commented 3 years ago

Tremendous help! Thank you Dale. I was able to get it working after a fair bit of testing.

Is there, by chance, a hook to update the information in the database?

dalenguyen commented 3 years ago

I'm happy to hear that! You can use the same hook to update data in firebase. It's the upsert function.