-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
62 lines (56 loc) · 1.61 KB
/
admin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
global $wpdb;
$results = $wpdb->get_results( 'SELECT `post_type` FROM wp_posts' );
$post_types = array();
foreach ($results as $post_type) {
array_push($post_types, $post_type->post_type);
}
$post_types = array_unique($post_types);
?>
<div class="wrap">
<h2>Favourite Posts</h2>
<form action="" method="POST">
<table class="form-table">
<tr>
<th scope="row"><label for="content_element">Select Element to append to</label></th>
<td><input id="content_element" type="text" name="content_element" value="<?php if(get_option( 'favourates_element' )) {
echo get_option( 'favourates_element' );
} ?>"></td>
</tr>
<tr>
<th scope="row"><label for="post_type">Post Types</label></th>
<td> <select name="post_type" id="post_type">
<?php
foreach ($post_types as $post_type) {
?>
<option value="<?php echo $post_type; ?>" <?php if(get_option( 'favourates_post_type' ) == $post_type) {
echo 'selected';
} ?>><?php echo $post_type ?></option>
<?php
}
?>
</select></td>
</tr>
</table>
<p>
<input type="submit" value="Update" class="button button-primary button-large">
</p>
</form>
<?php
if (isset($_POST['post_type'])) {
$type = $_POST['post_type'];
$post_ids = $wpdb->get_results( "SELECT `ID` FROM wp_posts WHERE post_type = '$type'" );
update_option( 'favourates_post_type', $_POST['post_type'], '', 'yes' );
}
if (isset($_POST['content_element'])) {
$type = $_POST['content_element'];
update_option( 'favourates_element', $type , '', 'yes' );
?>
<script>
jQuery(document).ready(function($) {
jQuery('#content_element').val("<?php echo $type; ?>");
});</script>
<?php
}
?>
</div>