• 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 years, 4 months ago by uamv.
    Thread Starter Loc Ho

    (@holoc)

    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' );
    } );
    Thread Starter Loc Ho

    (@holoc)

    Great thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘gt_post_type_selection’ is closed to new replies.