| 1 |
<p>Use this dropdown to select specific Page(s) or Post(s) where the script should output. If it's left blank, then the script will be global.</p> |
| 2 |
<select class="r8_tsm_page_select" name="r8_tsm_script_page[]" multiple="multiple"></select> |
| 3 |
|
| 4 |
<?php |
| 5 |
$post_types = get_post_types( array( 'public' => true ), 'objects', 'and' ); |
| 6 |
$data = array(); |
| 7 |
foreach ( $post_types as $post_type ) { |
| 8 |
if ( $post_type->name === 'attachment' ) { |
| 9 |
continue; |
| 10 |
} |
| 11 |
|
| 12 |
$args = array( |
| 13 |
'post_type' => $post_type->name, |
| 14 |
'status' => 'publish', |
| 15 |
'posts_per_page' => -1 |
| 16 |
); |
| 17 |
|
| 18 |
$posts = get_posts($args); |
| 19 |
|
| 20 |
if ( count($posts) > 0 ) { |
| 21 |
|
| 22 |
$children = array(); |
| 23 |
|
| 24 |
foreach ( $posts as $post ) { |
| 25 |
if ( is_array( $script_page ) && in_array( $post->ID, $script_page ) ) { |
| 26 |
$children[] = array( |
| 27 |
'id' => $post->ID, |
| 28 |
'text' => $post->post_title, |
| 29 |
'selected' => true |
| 30 |
); |
| 31 |
} else { |
| 32 |
$children[] = array( |
| 33 |
'id' => $post->ID, |
| 34 |
'text' => $post->post_title |
| 35 |
); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
$data[] = array( |
| 40 |
'text' => ucwords($post_type->labels->menu_name), |
| 41 |
'children' => $children |
| 42 |
); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
$data = json_encode($data); |
| 47 |
?> |
| 48 |
|
| 49 |
<script type="text/javascript"> |
| 50 |
var tsm_data = <?php echo $data; ?>; |
| 51 |
</script> |
| 52 |
|