PHP - Ocultar campo si elige una categoria

   
Vista:

Ocultar campo si elige una categoria

Publicado por ildefonso (1 intervención) el 01/06/2015 17:23:34
Hola, soy novato y estoy construyendo un portal de anuncios desde un theme en wordpress.
La cuestion es que necesito ocultar un campo a la hora de crear un nuevo anuncio , osea que este visible solo si se elige una categoria.
¿Podeis ayudarme?
Aquí os dejo el código.
Gracias a todos


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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<?php
 
if ( !is_user_logged_in() ) {
 
	global $redux_demo;
	$login = $redux_demo['login'];
	wp_redirect( $login ); exit;
 
} else {
 
}
 
 
$postTitleError = '';
$post_priceError = '';
$catError = '';
$featPlanMesage = '';
$postContent = '';
 
if(isset($_POST['submitted']) && isset($_POST['post_nonce_field']) && wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) {
 
	if(trim($_POST['postTitle']) === '') {
		$postTitleError = 'Please enter a title.';
		$hasError = true;
	} else {
		$postTitle = trim($_POST['postTitle']);
	}
 
	if(trim($_POST['catID']) === '-1') {
		$catError = 'Please select a category.';
		$hasError = true;
	}
 
 
 
	if($hasError != true) {
 
		$post_information = array(
			'post_title' => esc_attr(strip_tags($_POST['postTitle'])),
			'post_content' => esc_attr(strip_tags($_POST['postContent'])),
			'post-type' => 'post',
			'post_category' => array($_POST['catID']),
	        'tags_input'    => explode(',', $_POST['post_tags']),
	        'comment_status' => 'open',
	        'ping_status' => 'open',
			'post_status' => 'publish'
		);
 
 
		$post_id = wp_insert_post($post_information);
 
		$post_price_status = trim($_POST['post_price']);
 
		global $redux_demo;
		$free_listing_tag = $redux_demo['free_price_text'];
 
		if(empty($post_price_status)) {
			$post_price_content = $free_listing_tag;
		} else {
			$post_price_content = $post_price_status;
		}
 
		update_post_meta($post_id, 'post_category_type', esc_attr( $_POST['post_category_type'] ) );
		update_post_meta($post_id, 'custom_field', $_POST['custom_field']);
		update_post_meta($post_id, 'post_price', $post_price_content, $allowed);
		update_post_meta($post_id, 'post_location', wp_kses($_POST['post_location'], $allowed));
		update_post_meta($post_id, 'post_latitude', wp_kses($_POST['latitude'], $allowed));
		update_post_meta($post_id, 'post_longitude', wp_kses($_POST['longitude'], $allowed));
		update_post_meta($post_id, 'post_address', wp_kses($_POST['address'], $allowed));
		update_post_meta($post_id, 'post_video', $_POST['video'], $allowed);
 
		$permalink = get_permalink( $post_id );
 
 
		if(trim($_POST['edit-feature-plan']) != '') {
 
			$featurePlanID = trim($_POST['edit-feature-plan']);
 
			global $wpdb;
 
			global $current_user;
		    get_currentuserinfo();
 
		    $userID = $current_user->ID;
 
			$result = $wpdb->get_results( "SELECT * FROM wpcads_paypal WHERE main_id = $featurePlanID" );
 
			if ( $result ) {
 
				$featuredADS = 0;
 
				foreach ( $result as $info ) {
					if($info->status != "in progress" && $info->status != "pending") {
 
						$featuredADS++;
 
						if(empty($info->ads)) {
							$availableADS = "Unlimited";
							$infoAds = "Unlimited";
						} else {
							$availableADS = $info->ads - $info->used;
							$infoAds = $info->ads;
						}
 
						if(empty($info->days)) {
							$infoDays = "Unlimited";
						} else {
							$infoDays = $info->days;
						}
 
						if($info->used != "Unlimited" && $infoAds != "Ulimited" && $info->used == $infoAds) {
 
							$featPlanMesage = 'Please select another plan.';
 
						} else {
 
							global $wpdb;
 
							$newUsed = $info->used +1;
 
							$update_data = array('used' => $newUsed);
						    $where = array('main_id' => $featurePlanID);
						    $update_format = array('%s');
						    $wpdb->update('wpcads_paypal', $update_data, $where, $update_format);
						    update_post_meta($post_id, 'post_price_plan_id', $featurePlanID );
 
							$dateActivation = date('m/d/Y H:i:s');
							update_post_meta($post_id, 'post_price_plan_activation_date', $dateActivation );
 
							$daysToExpire = $infoDays;
							$dateExpiration_Normal = date("m/d/Y H:i:s", strtotime("+ ".$daysToExpire." days"));
							update_post_meta($post_id, 'post_price_plan_expiration_date_normal', $dateExpiration_Normal );
 
							$dateExpiration = strtotime(date("m/d/Y H:i:s", strtotime("+ ".$daysToExpire." days")));
							update_post_meta($post_id, 'post_price_plan_expiration_date', $dateExpiration );
 
							update_post_meta($post_id, 'featured_post', "1" );
 
					    }
					}
				}
			}
 
		}
 
 
		if ( $_FILES ) {
			$files = $_FILES['upload_attachment'];
			foreach ($files['name'] as $key => $value) {
				if ($files['name'][$key]) {
					$file = array(
						'name'     => $files['name'][$key],
						'type'     => $files['type'][$key],
						'tmp_name' => $files['tmp_name'][$key],
						'error'    => $files['error'][$key],
						'size'     => $files['size'][$key]
					);
 
					$_FILES = array("upload_attachment" => $file);
 
					foreach ($_FILES as $file => $array) {
						$newupload = wpcads_insert_attachment($file,$post_id);
					}
				}
			}
		}
 
		wp_redirect( $permalink ); exit;
 
	}
 
}
 
get_header(); ?>
 
	<?php while ( have_posts() ) : the_post(); ?>
 
	<section id="ad-page-title" class="add-new-post-header" >
 
        <div class="container">
 
        	<div class="span9 first">
        		<h2><?php the_title(); ?></h2>
 
        	</div>
 
        	<div class="span3"><h4 style="margin-top: 7px;"><?php _e('Account Overview', 'agrg') ?></h4></div>
 
        </div>
 
    </section>
 
    <section class="ads-main-page">
 
    	<div class="container">
 
	    	<div class="span9 first">
 
				<div id="upload-ad" class="ad-detail-content">
 
					<form class="form-item" action="" id="primaryPostForm" method="POST" enctype="multipart/form-data">
 
						<?php if($postTitleError != '') { ?>
							<span class="error" style="color: #d20000; margin-bottom: 20px; font-size: 18px; font-weight: bold; float: left;"><?php echo $postTitleError; ?></span>
							<div class="clearfix"></div>
						<?php } ?>
 
 
						<?php if($catError != '') { ?>
							<span class="error" style="color: #d20000; margin-bottom: 20px; font-size: 18px; font-weight: bold; float: left;"><?php echo $catError; ?></span>
							<div class="clearfix"></div>
						<?php } ?>
 
						<fieldset class="input-title">
 
							<label for="edit-title" class="control-label"><?php _e('Tu deseo *', 'agrg') ?></label>
							<input type="text" id="postTitle" name="postTitle" value="" size="60" maxlength="255" class="form-text required">
 
						</fieldset>
 
 
						<div id="edit-field-category">
							<div class="form-item">
								<label for="edit-field-category-und" class="control-label"><?php _e('Categoria *', 'agrg') ?></label>
 
								<?php wp_dropdown_categories( 'show_option_none=Category&hide_empty=0&hierarchical=1&id=catID' ); ?>
 
							</div>
						</div>
 
						<?php
				        	$args = array(
				        	  'hide_empty' => false,
							  'orderby' => count,
							  'order' => 'ASC'
							);
 
							$inum = 0;
 
							$categories = get_categories($args);
							  	foreach($categories as $category) {;
 
							  	$inum++;
 
				          		$user_name = $category->name;
				          		$user_id = $category->term_id;
 
 
				          		$tag_extra_fields = get_option(MY_CATEGORY_FIELDS);
								$wpcrown_category_custom_field_option = $tag_extra_fields[$user_id]['category_custom_fields'];
 
								if(empty($wpcrown_category_custom_field_option)) {
 
									$catobject = get_category($user_id,false);
									$parentcat = $catobject->category_parent;
 
									$wpcrown_category_custom_field_option = $tag_extra_fields[$parentcat]['category_custom_fields'];
								}
				          	?>
 
				          	<div id="cat-<?php echo $user_id; ?>" class="wrap-content" style="display: none;">
 
				             	<?php
				                	for ($i = 0; $i < (count($wpcrown_category_custom_field_option)); $i++) {
				              	?>
 
				                <fieldset class="input-title">
 
									<label for="edit-title" class="control-label"><?php if (!empty($wpcrown_category_custom_field_option[$i][0])) echo $wpcrown_category_custom_field_option[$i][0]; ?></label>
 
									<input type="hidden" class="custom_field" id="custom_field[<?php echo $i; ?>][0]" name="custom_field[<?php echo $i; ?>][0]" value="<?php echo $wpcrown_category_custom_field_option[$i][0] ?>" size="12">
 
									<input type="text" class="custom_field" id="custom_field[<?php echo $i; ?>][1]" name="custom_field[<?php echo $i; ?>][1]" value="" size="12">
 
								</fieldset>
 
				              	<?php
				                	}
				              	?>
 
 
				            </div>
 
				      	<?php } ?>
 
						<div id="price-field">
 
							<label for="edit-field-category-und" class="control-label"><?php _e('Price', 'agrg') ?></label>
							<input type="text" id="post_price" name="post_price" value="" size="12" class="form-text required">
							<p class="help-block"><?php _e('Leave empty for free listing', 'agrg') ?></p>
 
 
						</div>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder