Support » Plugin: Glance That » gt_post_type_selection

  • Resolved Loc Ho

    (@holoc)


    Hi,

    I’m trying to limit the available glances to only pages, posts, and custom events, but the function below doesn’t seem to be doing it. Am I using this filter correctly?

    add_filter( ‘gt_post_type_selection’, array(‘page’, ‘post’, ‘mec-events’) );

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author uamv

    (@uamv)

    You’ll need to do something like this. The array being passed through this filter is an array of post type objects. Even this, though, will only limit glances that are explicitly post types. It doesn’t touch on glances added directly in the plugin—things like Users, Comments, etc.

    add_filter( 'gt_post_type_selection', function( $post_types ) {
       foreach ( $post_types as $post_type => $object ) {
          if ( $post_type == 'post' ) { continue; }
          if ( $post_type == 'page' ) { continue; }
          if ( $post_type == 'mec-events' ) { continue; }
          unset( $post_types[ $post_type ] );
       }
       return $post_types;
    } );

    I’ll have to add a filter that will be more suitable for this—and easier to use.

    • This reply was modified 5 months, 1 week ago by uamv.

    Awesome, thank you @uamv for your speedy reply. That worked.
    Yes, maybe having something to simplify declaring it would be easier to use or leave an example of it in the documentation works as well.
    Thanks again for your assistance!

    Plugin Author uamv

    (@uamv)

    @holoc Version 4.7 adds a filter that can be used more nearly as you were intending. This should now also work:

    add_filter( 'gt_glance_selection', function( $options ) {
       return array( 'post', 'page', 'mec-events' );
    } );

    Great thank you!

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