@@ -197,7 +197,7 @@ public static function posts_meta_box( $post, $args ) {
197
197
?>
198
198
<optgroup label="<?php echo $ object ->labels ->name ; ?> ">
199
199
<?php
200
- printf ( '<option value="%s" data-post-type="%s">%s</option> ' , 0 , $ object ->labels ->singular_name , sprintf ( __ ( '— Add all %1$s (%2$s) — ' , 'ajaxd ' ), $ object ->labels ->name , sizeof ( $ posts ) ) );
200
+ printf ( '<option value="%s" data-post-type="%s">%s</option> ' , 0 , $ object ->labels ->singular_name , sprintf ( __ ( '— Add All %1$s (%2$s) — ' , 'ajaxd ' ), $ object ->labels ->name , sizeof ( $ posts ) ) );
201
201
foreach ( $ posts as $ post ):
202
202
printf ( '<option value="%s" data-post-type="%s">%s</option> ' , $ post ->ID , $ object ->labels ->singular_name , $ post ->post_title );
203
203
endforeach ;
@@ -264,6 +264,7 @@ public static function shortcode_meta_box( $post ) {
264
264
public static function method_meta_box ( $ post , $ args ) {
265
265
wp_nonce_field ( 'ajaxd_save_data ' , 'ajaxd_meta_nonce ' );
266
266
$ method = get_post_meta ( $ post ->ID , 'ajaxd_method ' , true );
267
+ $ no_content = get_post_meta ( $ post ->ID , 'ajaxd_no_content ' , true ) == 'yes ' ? true : false ;
267
268
$ method_options = array ( 'ajax ' => __ ( 'Ajax ' , 'ajaxd ' ), 'inline ' => __ ( 'Inline ' , 'ajaxd ' ), 'parameter ' => __ ( 'URL Parameter ' , 'ajaxd ' ), 'redirect ' => __ ( 'Redirect ' , 'ajaxd ' ) );
268
269
?>
269
270
<p class="howto">
@@ -278,6 +279,13 @@ public static function method_meta_box( $post, $args ) {
278
279
?>
279
280
</select>
280
281
</p>
282
+ <p class="ajaxd-no-content-option">
283
+ <label>
284
+ <input type="hidden" name="ajaxd_no_content" value="no">
285
+ <input type="checkbox" name="ajaxd_no_content" class="ajaxd-no-content" value="yes" <?php checked ( $ no_content ); ?> >
286
+ <?php _e ( 'Dropdown only (no content) ' , 'ajaxd ' ); ?>
287
+ </label>
288
+ </p>
281
289
<?php
282
290
}
283
291
@@ -306,6 +314,10 @@ public static function save_meta_boxes( $post_id, $post ) {
306
314
update_post_meta ( $ post_id , 'ajaxd_layout ' , 'dropdown ' );
307
315
if ( isset ( $ _POST ['ajaxd_method ' ] ) )
308
316
update_post_meta ( $ post_id , 'ajaxd_method ' , $ _POST ['ajaxd_method ' ] );
317
+ if ( isset ( $ _POST ['ajaxd_method ' ] ) && 'redirect ' == $ _POST ['ajaxd_method ' ] && isset ( $ _POST ['ajaxd_no_content ' ] ) )
318
+ update_post_meta ( $ post_id , 'ajaxd_no_content ' , $ _POST ['ajaxd_no_content ' ] );
319
+ else
320
+ update_post_meta ( $ post_id , 'ajaxd_no_content ' , 'no ' );
309
321
}
310
322
311
323
/**
@@ -343,8 +355,9 @@ public static function shortcode( $atts ) {
343
355
else
344
356
$ current = reset ( $ include );
345
357
346
- // Get method
358
+ // Get method and no content option
347
359
$ method = get_post_meta ( $ id , 'ajaxd_method ' , true );
360
+ $ no_content = get_post_meta ( $ id , 'ajaxd_no_content ' , true );
348
361
349
362
/**
350
363
* Select options
@@ -368,32 +381,37 @@ public static function shortcode( $atts ) {
368
381
$ script = '$("#ajaxd-select- ' . $ id . '").change(function(){$.post(" ' . admin_url ('admin-ajax.php ' ) . '",{"action":"ajax_dropdown","post_id":$(this).val()},function(response){if(response!=0){$("#ajaxd-posts- ' . $ id . '").html(response)};});}); ' ;
369
382
endif ;
370
383
371
- // Get global $wp_query and hold onto original queried object
372
- global $ wp_query ;
373
- $ queried_object = $ wp_query ->queried_object ;
384
+ // Skip if no content
385
+ if ( 'yes ' == $ no_content ):
386
+ $ content = '' ;
387
+ else :
388
+ // Get global $wp_query and hold onto original queried object
389
+ global $ wp_query ;
390
+ $ queried_object = $ wp_query ->queried_object ;
391
+
392
+ // Limit posts to current if not inline
393
+ if ( 'inline ' != $ method ):
394
+ $ include = array ( $ current );
395
+ endif ;
396
+
397
+ // Loop through posts
398
+ $ content = '<div class="ajaxd-posts" id="ajaxd-posts- ' . $ id . '"> ' ;
399
+ foreach ( $ include as $ post_id ):
400
+ $ query = new WP_Query ( array ( 'p ' => $ post_id , 'post_type ' => 'any ' ) );
401
+ if ( ! $ query ->have_posts () ) continue ;
402
+ while ( $ query ->have_posts () ): $ query ->the_post ();
403
+ global $ post ;
404
+ $ wp_query ->queried_object = $ post ;
405
+ $ content .= '<div class="ajaxd-post" id="ajaxd-post- ' . $ post_id . '" ' . ( $ current == $ post_id ? '' : ' style="display:none;" ' ) . '> ' . apply_filters ( 'the_content ' , get_the_content () ) . '</div> ' ;
406
+ endwhile ;
407
+ endforeach ;
408
+ wp_reset_postdata ();
409
+ $ content .= '</div><!-- .ajaxd-posts --> ' ;
374
410
375
- // Limit posts to current if not inline
376
- if ( 'inline ' != $ method ):
377
- $ include = array ( $ current );
411
+ // Restore original queried object
412
+ $ wp_query ->queried_object = $ queried_object ;
378
413
endif ;
379
414
380
- // Loop through posts
381
- $ content = '<div class="ajaxd-posts" id="ajaxd-posts- ' . $ id . '"> ' ;
382
- foreach ( $ include as $ post_id ):
383
- $ query = new WP_Query ( array ( 'p ' => $ post_id , 'post_type ' => 'any ' ) );
384
- if ( ! $ query ->have_posts () ) continue ;
385
- while ( $ query ->have_posts () ): $ query ->the_post ();
386
- global $ post ;
387
- $ wp_query ->queried_object = $ post ;
388
- $ content .= '<div class="ajaxd-post" id="ajaxd-post- ' . $ post_id . '" ' . ( $ current == $ post_id ? '' : ' style="display:none;" ' ) . '> ' . apply_filters ( 'the_content ' , get_the_content () ) . '</div> ' ;
389
- endwhile ;
390
- endforeach ;
391
- wp_reset_postdata ();
392
- $ content .= '</div><!-- .ajaxd-posts --> ' ;
393
-
394
- // Restore original queried object
395
- $ wp_query ->queried_object = $ queried_object ;
396
-
397
415
// Return output
398
416
return $ select . $ content . '<script type="text/javascript">(function($) { ' . $ script . '})(jQuery);</script> ' ;
399
417
}
0 commit comments