Title: Filter by current post?
Last modified: November 7, 2021

---

# Filter by current post?

 *  Resolved [razor89](https://wordpress.org/support/users/razor89/)
 * (@razor89)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/filter-by-current-post/)
 * Hello,
 * Can we filter the export file based on current embedded post and current author?
 * I noticed this is possible using filter
 * But I’m not sure how to do it?
 * Can you guide me?
 * Thank you so much

Viewing 13 replies - 1 through 13 (of 13 total)

 *  Plugin Author [Doeke Norg](https://wordpress.org/support/users/doekenorg/)
 * (@doekenorg)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/filter-by-current-post/#post-15044190)
 * Hi [@razor89](https://wordpress.org/support/users/razor89/),
 * I’m not completely sure what you mean. Do you want to filter the results of the
   normal output (so the public download url without any filters attached) based
   on the current logged in user, where that user is also the creator of the entry?
 * And what do you mean by embedded post. It’s probably possible; but I would like
   a full example to create a hook you could use.
 * Thanks.
 *  Thread Starter [razor89](https://wordpress.org/support/users/razor89/)
 * (@razor89)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/filter-by-current-post/#post-15044231)
 * I used one form for all custom post that created by users.
 * If I don’t use filter, all data from all custom post from different author will
   be appear in the download file.
 * So I just want if user download the file, the data will be based on their own
   post.
 * Btw one user just can create 1 custom post.
 * hopefully you know what I mean.
 * Thank you so much for the help.
 *  Plugin Author [Doeke Norg](https://wordpress.org/support/users/doekenorg/)
 * (@doekenorg)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/filter-by-current-post/#post-15044394)
 * [@razor89](https://wordpress.org/support/users/razor89/) so does that mean the
   results will only include one result, because the user can have only one post?
 * Or are there separate entries based on a post that is connected to the user?
 * Can you perhaps send me an export of your form (as .json) and an example file
   of what you would like it to include?
 * Please send it to [wordpress@doeken.org](https://wordpress.org/support/topic/filter-by-current-post/wordpress@doeken.org?output_format=md)
 * Thanks!
 *  Plugin Author [Doeke Norg](https://wordpress.org/support/users/doekenorg/)
 * (@doekenorg)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/filter-by-current-post/#post-15044880)
 * [@razor89](https://wordpress.org/support/users/razor89/) I figured I’ll at least
   send you this hook. This will filter the results on the current logged in user.
   If you can get the post id you need, that you can also filter on that post id.
   Just remove whichever filter you do not want.
 * Hope this helps.
 *     ```
       /**
        * Hook that filters gravity export results on the current user and post id.
        */
       add_filter( 'gfexcel_output_search_criteria', function ( array $search_criteria ) {
       	// filter entries created by current user.
       	$search_criteria['field_filters'][] = [
       		'key'   => 'created_by',
       		'value' => get_current_user_id(),
       	];
   
       	$post_id = 1; // find a way to fill this variable
       	// filter entries on post id
       	$search_criteria['field_filters'][] = [
       		'key'   => 'post_id',
       		'value' => $post_id,
       	];
   
       	return $search_criteria;
       } );
       ```
   
    -  This reply was modified 4 years, 7 months ago by [Doeke Norg](https://wordpress.org/support/users/doekenorg/).
      Reason: fix indenting
 *  Thread Starter [razor89](https://wordpress.org/support/users/razor89/)
 * (@razor89)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/filter-by-current-post/#post-15050705)
 * Sorry for late reply, thank you so much [@doekenorg](https://wordpress.org/support/users/doekenorg/)
 * I tried the code, but looks like the result just the current user who fill the
   form.
 * Maybe if nice if the result will be based on source url of the form.
 * Thank you
 *  Thread Starter [razor89](https://wordpress.org/support/users/razor89/)
 * (@razor89)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/filter-by-current-post/#post-15050712)
 * or permalink it’s okay too
 *  Plugin Author [Doeke Norg](https://wordpress.org/support/users/doekenorg/)
 * (@doekenorg)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/filter-by-current-post/#post-15054724)
 * Hi [@razor89](https://wordpress.org/support/users/razor89/) ,
 * Sorry, but I’m having trouble understanding your question.
 * You said filter on the current author; maybe you are talking about the other 
   of a post? I’m very confused.
 * 1. What does your form do? Does it create posts?
    2. Do you have one form on 
   multiple pages? And do you need the entries posted from that page? 3. Can you
   give me step by step how a post is filled, what it contains, and what you would
   like as the result? Please leave no detail out. 4. Please provide your form as
   a .json to `wordpress@doeken.org`. This will probably help in clearing this up.
 * Thanks, and again sorry for my confusion.
 *  Thread Starter [razor89](https://wordpress.org/support/users/razor89/)
 * (@razor89)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/filter-by-current-post/#post-15105498)
 * Hello Doeke,
    sorry for late respond.
 * 1. What does your form do? Does it create posts?
    No, just to create the comment.
   so the form just use to create comment (to replace the default comment in WordPress)
   2. Do you have one form on multiple pages? And do you need the entries posted
   from that page? yes one form for multiple pages, just need to filter the entries
   based on each post and author of current post can download it. 3. Can you give
   me step by step how a post is filled, what it contains, and what you would like
   as the result? Please leave no detail out. I’m using acf to create the post (
   one post per user). The result will be all entries based on current author of
   the post
 * 4. for sure will send it now
 * Btw thank you so much for your support, really appreciate it.
 *  Plugin Author [Doeke Norg](https://wordpress.org/support/users/doekenorg/)
 * (@doekenorg)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/filter-by-current-post/#post-15110431)
 * Hi [@razor89](https://wordpress.org/support/users/razor89/),
 * Thank you for providing this context. This helped a lot. I think this is what
   you need:
 * I used a form with the id `51`. Please update the filter with the correct form_id
   for your form. Since you provided me with your form, the field id (`4`) should
   be correct.
 * This code will retrieve all page id’s the current user has made. Then it will
   filter all results to only include any entries that were posted on pages that
   have one of those ID’s. This makes it so you can use this for multiple pages 
   for the same person too, but also just for a single page.
 * Hope this helps you out.
 *     ```
       /**
        * Hook that filters gravity export results for the current user.
        */
       add_filter( 'gfexcel_output_search_criteria_51', function ( array $search_criteria ) {
       	$ids = get_posts( [
       		'author'      => get_current_user_id(),
       		'fields'      => 'ids', // We're only interested in the id's of these pages / posts
       		'status'      => 'publish', // only check for published pages
       		'post_type'   => 'page', // if it is a post (and not a page) you can remove this line
       		'numberposts' => - 1, // all results
       	] );
   
       	// filter entries on post id
       	$search_criteria['field_filters'][] = [
       		'key'      => 4,
       		'operator' => 'IN',
       		'value'    => $ids,
       	];
   
       	return $search_criteria;
       } );
       ```
   
 *  Thread Starter [razor89](https://wordpress.org/support/users/razor89/)
 * (@razor89)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/filter-by-current-post/#post-15122150)
 * I’m sorry Doeke
 * It didn’t work, I tried in several past days but still not work.
 * But thank you so much for your help
 *  Plugin Author [Doeke Norg](https://wordpress.org/support/users/doekenorg/)
 * (@doekenorg)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/filter-by-current-post/#post-15122161)
 * [@razor89](https://wordpress.org/support/users/razor89/) can you provide an environment
   that doesn’t work I can fix? Or can we use a chat service to have a quick chat
   to fix this?
 * Please let me know on [wordpress@doeken.org](https://wordpress.org/support/topic/filter-by-current-post/wordpress@doeken.org?output_format=md)
 *  Thread Starter [razor89](https://wordpress.org/support/users/razor89/)
 * (@razor89)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/filter-by-current-post/#post-15152748)
 * Hi [@doekenorg](https://wordpress.org/support/users/doekenorg/)
 * all is good now and the data filtered based on post id now 🙂
 * Thank you so much, and I really appreciate it for your help
 * Btw I changed the code with this below:
 * `/**
    * Hook that filters gravity export results for the current user. */ add_filter(‘
   gfexcel_output_search_criteria’, function ( array $search_criteria ) { $ids =
   get_posts( [ ‘author’ => get_current_user_id(), ‘fields’ => ‘ids’, // We’re only
   interested in the id’s of these pages / posts ‘status’ => ‘publish’, // only 
   check for published pages ‘post_type’ => ‘custom_post’, //I change this with 
   my custom post type ‘numberposts’ => 1, // all results ] );
 *  // filter entries on post id
    $search_criteria[‘field_filters’][] = [ ‘key’ 
   => 4, ‘operator’ => ‘IN’, ‘value’ => $ids, ];
 *  return $search_criteria;
    } );
 *  Plugin Author [Doeke Norg](https://wordpress.org/support/users/doekenorg/)
 * (@doekenorg)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/filter-by-current-post/#post-15157540)
 * [@razor89](https://wordpress.org/support/users/razor89/) thanks for letting me
   know. Glad it worked out!

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Filter by current post?’ is closed to new replies.

 * ![](https://ps.w.org/gf-entries-in-excel/assets/icon.svg?rev=3434379)
 * [GravityExport Lite for Gravity Forms](https://wordpress.org/plugins/gf-entries-in-excel/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/gf-entries-in-excel/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/gf-entries-in-excel/)
 * [Active Topics](https://wordpress.org/support/plugin/gf-entries-in-excel/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gf-entries-in-excel/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gf-entries-in-excel/reviews/)

 * 13 replies
 * 2 participants
 * Last reply from: [Doeke Norg](https://wordpress.org/support/users/doekenorg/)
 * Last activity: [4 years, 5 months ago](https://wordpress.org/support/topic/filter-by-current-post/#post-15157540)
 * Status: resolved