Post Timeline Filter Hooks

The Post Timeline plugin offers several filter hooks that allow users to manipulate timeline post data, customize display formats, and integrate custom fields. Below is a table of the available filter hooks and their descriptions:

Filter HookDescription
ptl_filter_timeline_postAllows manipulation of timeline post data, including custom fields.
ptl_layout_overrideModify the class so you create your own kind of timeline.

Example: Adding Custom Fields to the Timeline #

To manipulate the timeline data and include custom fields (created by plugins like Toolset Types), you can add custom logic to your theme’s functions.php file. In this example, we’ll change the post date and convert images into a gallery for the timeline.

/**
 * Modify timeline post data to include custom date and gallery.
 */
add_filter('ptl_filter_timeline_post', function($_post) {

  // Update the date field using the 'wpcf-date' custom field
  if(isset($_post->custom['wpcf-date'][0]) && $_post->custom['wpcf-date'][0]) {
    $timestamp = $_post->custom['wpcf-date'][0];
    $_post->custom['ptl-post-date'] = [date('Y-m-d', $timestamp)];  // Set the date format
  }

  // Convert 'wpcf-picture' custom field into a gallery
  if(isset($_post->custom['wpcf-picture'][0]) && $_post->custom['wpcf-picture'][0]) {
    $attachments = [];

    // Loop through each attachment URL and get its ID
    foreach($_post->custom['wpcf-picture'] as $attachment) {
      $attachment_id = ptl_get_attachment_id_by_url($attachment);

      if($attachment_id) {
        $attachments[] = $attachment_id;
      }
    }

    // Set up a gallery and media type for the timeline
    $_post->custom['ptl_gallery']    = [implode(',', $attachments)];
    $_post->custom['ptl-media-type'] = ['gallery'];
  }

  return $_post;
});

Explanation: #

  1. Custom Date (wpcf-date): The custom field wpcf-date (created using Toolset Types) is retrieved, converted to a date format (Y-m-d), and set in the timeline under the ptl-post-date key.
  2. Gallery (wpcf-picture): The custom field wpcf-picture, containing image URLs, is converted into a gallery by obtaining the attachment IDs and setting them in the ptl_gallery field.

You can adjust the code based on your custom fields and data handling needs.