• Resolved hasanfachrul

    (@hasanfachrul)


    how can I use pods block item list to list all the custom post type where custom fields is current user?

    I have certificate custom post type, and want to list all the certificates based on the current user id

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Paul Clark

    (@pdclark)

    First, enable Dynamic Features in Pods Admin > Settings > Security section so that the block WHERE field displays.

      Option 1:

      1. Use magic tags by adding define( 'PODS_SHORTCODE_ALLOW_EVALUATE_TAGS', true ); to wp-config.php
      2. Use {@user.ID} IN( custom_field_name.ID ) for the WHERE query, meaning the current user ID is found in a field named custom_field_name on the queried pod, which would be a relationship field connected to users.

      Option 2:

      If channging wp-config.php is challenging or the magic tag {@user.ID} does not work as expected, add this PHP code snippet with a plugin like Code Snippets:

      add_filter(
      'pods_pods_find',
      function( $params ) {
      $params = (array) $params;
      if ( array_key_exists( 'where', $params ) ) {
      $params['where'] = str_replace(
      'CURRENTUSERID',
      get_current_user_id(),
      (string) $params['where']
      );
      }
      return (object) $params;
      }
      );

      Then use CURRENTUSERID IN( custom_field_name.ID ) as the WHERE query, with the same custom_field_name.ID assumption as above.

      Thread Starter hasanfachrul

      (@hasanfachrul)

      I see, it still doesn’t work. I have a custom field called achiever (it’s a relation field to user) but the magic tags for achiever doesn’t show up on pod templates. is it the problem?

      Plugin Support Paul Clark

      (@pdclark)

      Apologies for the delayed follow-up.

      If {@achiever} and [each achiever]{@user_login}[/each] don’t display anything in the templates, make sure the Pod Block or shortcode is querying the post type certificate

      The code provided previously was for modifying the WHERE field on the Block, which displays if SQL is enabled in Pods Admin > Settings

      If it’s still challenging, please open a new ticket with more details about the setup or join the support chat on Slack using the link at support.pods.io

    Viewing 3 replies - 1 through 3 (of 3 total)
    • You must be logged in to reply to this topic.