• pythonidea

    (@pythonidea)


    Hi, I am trying to hook the gallery shortcode of wp but ithe ids returns empty. this is my code:

    add_filter( 'post_gallery', 'semantic_gallery2', 10, 2 );
    
    function semantic_gallery2( $attr) {
    	$post = get_post();
    
    	static $instance = 0;
    	$instance++;
    
    	//
    	if ( ! empty( $attr['ids'] ) ) {
    		// 'ids' is explicitly ordered, unless you specify otherwise.
    		if ( empty( $attr['orderby'] ) )
    			$attr['orderby'] = 'post__in';
    		$attr['include'] = $attr['ids'];
    	}
    
    	if ( isset( $attr['orderby'] ) ) {
    		$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
    		if ( !$attr['orderby'] )
    			unset( $attr['orderby'] );
    	}
    
    	extract( shortcode_atts( array(
    		'order'      => 'ASC',
    		'orderby'    => 'menu_order ID',
    		'id'         => $post->ID,
    		'itemtag'    => 'dl',
    		'icontag'    => 'dt',
    		'captiontag' => 'dd',
    		'columns'    => 3,
    		'size'       => 'large',
    		'include'    => $attr['include'],
    		'exclude'    => '',
    		'link'       => '',
    	), $attr, 'gallery' ) );
    
    ....

    this is the shortcode:

    [gallery columns="4" ids="11633,11632"]

    in default, the ids is not empty, I was wondering that when I hook it, it became empty… I have already took the same code of the media.php…

    please help…

  • The topic ‘hooked gallery shortcode attributes returns empty’ is closed to new replies.