Set up the Integration

Some advice before we begin

  • It is important to note that there are many lines of code inside the FileMaker calculation dialog that are commented out by adding // to the beginning of the line. Any code with // to the left does not evaluate and therefore does not effect the outcome of the calculation.
  • It is best to follow the instructions exactly until you get a working prototype. Then, take a backup and feel free to experiment. Please do not modify and field names, script names, etc until you are completely done with this tutorial. There are a lot of dependencies. For example, if you import custom functions and change their names before you import the scripts, the scripts will import with hundreds of errors. Once you are entirely done with this tutorial, you can rename but still proceed with caution.
  • We will be working with a pre-written code repository. You can, however, write your own code from scratch. The WordPress FileMaker Sync plugin itself is essentially a direct port of the WordPress FileMaker XMLRPC API. The raw documentation can be found here.

The video tutorials can be found on the right hand side of the screen.

Import Custom Functions

  1. Open your file in FileMaker Pro Advanced. If you do not have FileMaker Pro Advanced on your machine, switch to a machine with it installed or contact us to help you with your deployment.
  2. From the top menu, navigate to File > Manage > Custom Functions...
  3. File > Manage > Custom Functions...

    File > Manage > Custom Functions…

  4. On the Manage Custom Functions screen, click Import.
  5. Click Import

    Click Import

  6. On the Open File dialog, navigate to the Code Repository.fmp12 in your download from WordPress FileMaker Sync. Click Open.
  7. Select the Code Repository.fmp12

    Select the Code Repository.fmp12

  8. On the Import Custom Function dialog, check the checkbox to the left of every function. Click OK.
  9. Check all the checkboxes. Click OK.

    Check all the checkboxes. Click OK.

  10. Review the Import Summary. Click OK.
  11. Review Import Summary

    Review Import Summary

  12. Click OK to close the Manage Custom Functions dialog.

Add WordPress-specific fields to FileMaker

To make life easier, we’re first going to change the table name in Code Repository.fmp12 to match the table name in your file.

  1. First, head over to your file, click File > Manage > Database... to open up the Manage Database Dialog.
  2. File > Manage > Database...

    File > Manage > Database…

  3. In the Manage Database dialog, click on the Tables tab. Select the table you want to sync to WordPress and select the text in the the Table Name: field at the bottom. Use Command + C (Mac) or Ctrl + C (Windows) not the Copy button to copy the text.
  4. Table tab

    Click table tab and copy your table name.

  5. Now, alongside your file, open the Code Repository.fmp12 found in your download package.
  6. In Code Repository.fmp12, click File > Manage > Database... to open up the Manage Database Dialog.
  7. File > Manage > Database...

    File > Manage > Database…

  8. Select the Tables tab. Select the table named table and paste your copied table name into the Table Name: field at the bottom. Click Change.
  9. Select 'table' table in Code Repository.fmp12

    Select ‘table’ table in Code Repository.fmp12

  10. Now, flip over to the Fields tab. Select these fields and click Copy.
  11. post_id Number
    post_error Text
    wordpress_status Number
    post_timestamp Timestamp
    edit_timestamp Calculation
    has_been_edited_since_post Calculation
    Copy selected fields on fields tab

    Copy selected fields on fields tab

  12. Flip back to Product Catalog.fmp12, click File > Manage > Database... to open up the Manage Database Dialog.
  13. File > Manage > Database...

    File > Manage > Database…

  14. In the Manage Database dialog, click on the Tables tab. Double-click the table you want to sync to WordPress. Click Paste. Click OK to close the Manage Database dialog.
  15. Paste fields

    Paste fields

    You may notice that edit_timestamp field is commented out. Just leave it for now. We will modify this at a later time.

    Import Scripts

    1. In your file, navigate to Scripts > Scripts Workspace... from the top menu.
    2. Scripts > Scripts Workspace...

      Scripts > Scripts Workspace…

    3. With Script Workspace open, select Scripts > Import...
    4. Scripts > Import...

      Scripts > Import…

    5. Select the Code Repository.fmp12 file. Click Open.
    6. Open the Code Repository.fmp12

      Open the Code Repository.fmp12

    7. On the Import Scripts screen, check all the Call Samples and Modular Scripts but none of the Utility scripts. Click OK.
    8. Check all the scripts except the utility scripts.

      Check all the scripts except the utility scripts.

    9. Review the Import Summary. There should be 3 errors. If you see hundreds, make sure you imported the correct fields, renamed the table in Code Repository to match your table and have imported the custom functions. In short, make sure you followed the instructions above. If you have more than 3 errors, delete the scripts you just imported, fix the issues and re-import.
    10. Import Summary

      Import Summary

    Modify Post Title and Content

    1. In the Script Workspace, click New or Edit Post with Upload File on the left hand side of the screen. Scroll down and double-click the script line that begins Set Variable [ $post_title; ...
    2. Select script and Set Variable $post_title line

      Select script and Set Variable $post_title line

    3. Click Specify… for the Value: line
    4. Modify Post Title

      Modify Post Title

    5. First, remove the comment brackets /* at the beginning of the calculation and */ at the end of the calculation. Next, build a calculation of your fields on the line that currently has
      your_table_name::sample_field & " - " & your_table_name::another_field

      For example, you could just put one field there like this:

      table::title

      Click OK twice when you’re done.

    6. ecsr-set-title

    7. Scroll down and double-click the script line that begins Set Variable [ $post_content; ...
    8. double-click the Set Variable [ $post_content... line

      double-click the Set Variable [ $post_content… line

    9. Click Specify… for the Value: line
    10. Click the top Specify... button

      Click the top Specify… button

    11. First, remove the comment brackets /* at the beginning of the calculation and */ at the end of the calculation. Next, build a calculation of your fields on the line that currently has
      your_table_name::sample_field & " - " & your_table_name::another_field

      For example, you could just put one field there like this:

      table::title

      Click OK twice when you’re done.

    12. Edit the calculation for the $post_content variable

      Edit the calculation for the $post_content variable

    Set xmlrpc, blog id, username and password

    1. Head back over to the Code Repository.fmp12. If you did the Test Post (if not, do it now), your xmlrpc will still be displayed at the bottom of the screen. Click to copy.
    2. Click to copy the xmlrpc value

      Click to copy the xmlrpc value

    3. Back in your file in the Scripts Workspace, open New or Edit Post with Upload File. Double-click the line that begins Set Variable [ $xmlrpc... .
    4. Double-click Set Variable [ $xmlrpc ... script step

      Double-click Set Variable [ $xmlrpc … script step

    5. Click Specify
    6. Click Specify...

      Click Specify…

    7. Where it says, "http://yourwebsite.com/xmlrpc.php" paste the copied xmlrpc value inside quotes ( “” ). Click OK twice.
    8. Paste your xmlrpc value inside quotes

      Paste your xmlrpc value inside quotes

    9. You can probably leave the Set Variable script step for $blog_id alone. It is set to 1 by default. If your site is hosted on wordpress.com or you have multiple WordPress installation on a single blog, you can use the included wp_getUsersBlogs FileMaker external function to discover your blog id.
    10. For both the Set Variable script steps for $username and $password, enter the username and password (between quotes) you enter on your WordPress dashboard login page in the Specify Value field. It will be the same as the pair used in the Test Post steps above.

    Post Criteria

    The top two Set Variable script steps in the New or Edit Post with Upload File script are $field_name_post_criteria and $post_criteria. The value for $field_name_post_criteria should be GetFieldName ( your-table-here::wordpress_status ). If this isn’t true, you either did not create the wordpress_status field or did not change the table name in the Code Repository to match your table name exactly before importing the scripts. The value for $post_criteria is 1. What this means is that the wordpress_status field needs to hold the value 1 or it will not be posted. This allows you to select which records you want to post to WordPress and leave some behind. You can now make wordpress_status a field that returns 1 only if it is to be posted if you would like. For now, we need to make sure wordpress_status holds the value 1 before we can test out our setup thus far.

    1. In FileMaker, navigate to the layout you want to post FileMaker records from. It should have the same context as the table you created all the new fields in in previous steps.
    2. View > Layout Mode
    3. View > Layout Mode

      View > Layout Mode

    4. Insert > Field
    5. Insert > Field

      Insert > Field

    6. Check ‘Create Label’. Double-click the wordpress_status field.
    7. Select wordpress_status field

      Select wordpress_status field

    8. Drag the field and label where you want it to be.
    9. While we’re here, we’re also going to add the field that displays any errors wordpress returns.

    10. Insert > Field
    11. Insert > Field

      Insert > Field

    12. Check ‘Create Label’. Double-click the post_error field.
    13. Select wordpress_status field

      Select wordpress_status field

    14. Drag the field and label where you want it to be.
    15. View Browse Mode.
    16. View > Browse Mode...

      View > Browse Mode…

    17. Records > Show All Records. If its greyed-out thats fine. That means you’re already looking at all the records.
    18. Records > Show All

      Records > Show All

    19. Click into the newly created wordpress_status field. Type 1.
    20. (Only perform this step if you want ALL records to post.) While your cursor is still in the wordpress_status field, Records > Replace Field Contents… Make sure the selected radio button says Replace with “1”. Click Replace.
    21. Records > Replace Field Contents

      Records > Replace Field Contents

      Let’s test the setup on just one for now.

    Test Setup So Far

    The default post status is draft. We’re going to leave that for now so we can test our setup thus far. This can be modified later by changing the Set Variable [ $post_status script in the New or Edit Post with Upload File script.

    1. Navigate to the layout you want to post to WordPress from and the record you’d like to test first. From the Scripts Menu, open the Scripts Workspace. Select New or Edit Post with Upload File and then click the play button at the top of the Scripts Workspace.
    2. Run the script from the Scripts Workspace

      Run the script from the Scripts Workspace

    3. Now, have a look at the post_error field. If its empty, you successfully posted! If its not, please read it and try to resolve the error. If you don’t understand the error, please copy/paste it into an email and email it to lauren@wordpressfilemaker.com and say you were trying to post for the first time from your own file. Please always include your xmlrpc value and the exact error message when contacting us for support.

    Add button to View Post

    1. With your file open in FileMaker, click Insert > Button.
    2. Insert > Button

      Insert > Button

    3. Enter a label such as ‘View Post’. For action, choose Single Step
    4. Label the button and choose Action: Single Step

      Label the button and choose Action: Single Step

    5. In the search box, type ‘Open URL’ and double-click the resulting Open URL script step. Click the blue cog to the right of the Open URL script step on the left.
    6. Select the Open URL script step and then click the "blue cog"

      Select the Open URL script step and then click the “blue cog”

    7. Check ‘Perform without Dialog’ and Click Specify...
    8. Check 'Perform without dialog' and click Specify.

      Check ‘Perform without dialog’ and click Specify.

    9. Click Specify... again.
    10. Click Specify...

      Click Specify…

    11. Copy the code below and paste it into the calculation dialog.
      "http://yourwebsite.com/?p=" & your_table::post_id
    12. Copy and paste the code below into the calculation dialog

      Copy and paste the code below into the calculation dialog

    13. Replace yourwebsite.com with your website url. Replace your_table with the name of the table that holds your post_id field.
    14. Click OK thrice and close the button setup. Drag the button to the location you’d like.
    15. View > Browse Mode.
    16. View > Browse Mode...

      View > Browse Mode…

    17. Click View Post. Your post should appear in the browser.

    Set up Edit Timestamp

    The edit_timestamp field exists so that only records that have the fields that are sent to WordPress modified since the last time they were posted to WordPress are reposted. It saves time and bandwidth. Let’s set that up now.

    1. With your file open in FileMaker, File > Manage > Database…
    2. File > Manage > Database...

      File > Manage > Database…

    3. Choose the tables tab. Navigate to the table you are posting to WordPress from. Double-click the edit_timestamp field.
    4. Double-click edit_timestamp

      Double-click edit_timestamp

      You may need to refer to the New or Edit Post with Upload File script to ensure you list all the fields referenced in the set variable script steps at the top of the script.

    5. First, remove the /* at the beginning and */ at the end of the calculation. Next, read through the directions inside the script comments.
    6. Edit the timestamp calculation as per the comments inside the dialog

      Edit the timestamp calculation as per the comments inside the dialog

    7. When you are done, click OK twice to exit.