Insert woocommerce products programmatically with featured image and gallery
Insert woocommerce products programmatically with featured image and gallery
Insert woocommerce products programmatically with featured image and gallery
Populate dropdown with Child Pages based on Parent Page chosen
One (untested) suggestion is to replace: unset( $classes[array_search($body_classes, $classes)] ); with $classes = array_diff( $classes, wp_parse_slug_list( $body_classes ) ); assuming the classes survive sanitize_title from wp_parse_slug_list(). It should also be alright with empty arrays. We also note that wp_parse_slug_list() is using wp_parse_list() to parse the comma separated string.
It’s a serialized string. Use Unserialize to get an array out of this. Also checkout WP’s maybe_unserialize method. <?php $string = “s:19.a:1:{i:0;s2”; //Using WP maybe_unserialize $result1 = maybe_unserialize($string); //Using PHP unserialize $result2 = unserialize($string); echo “<pre>”; print_r($result1); print_r($result2) echo “</pre>”; ?> $result will hold what you want.
John, I’m not sure how you have the radio button set up, but WordPress easily handles multiple values in one meta_key. You simply need to place the values in an array before sending it to update_post_meta. For instance: $array = array( ‘foo’ => ‘foo_value’, ‘bar’ => ‘bar_value’ ); update_post_meta( $id, ‘my_meta_key’, $array ); WordPress automatically … Read more
Use the Settings API. A look at my latest plugin may help you to understand how to register a save function for your fields. Most relevant excerpt: /** * Register custom settings for the fields. * * @see save_settings() * @see print_input_field() * @return void */ public function add_contact_fields() { register_setting( ‘general’, $this->option_name, array ( … Read more
If I’m understanding your issue correctly, and if by ‘project title’ you mean the content of the post_title field, then it’ll look something like this: $post_data = array(); $my_query = new WP_Query( $whatever_your_args_are ); if ( $my_query->have_posts() ) { while ( $my_query->have_posts() ) { $my_query->the_post(); $post_data[] = array( ‘project_title’ => get_the_title(), ‘latitude’ => get_post_meta( get_the_ID(), … Read more
Aha! I think I found your answer. Two facts: The description of the $meta_value argument on add_post_meta() functions’s codex page notes: An array will be serialized into a string. The $single argument’s description on the get_post_meta() function’s codex page notes: If set to true then the function will return a single result, as a string. … Read more
You can’t, at least not efficiently. You best bet is to use the LIKE statement, but it would fail for searches like “title”, “link”, “mp3” 🙂 I suggest you build your own serialization method. For example, store the tracklist as a string like this: Track1 title Track2 title Notice the new line character (\n). Use … Read more
use php’s implode to join array elements with a string: <?php if( $bands = get_post_meta($post->ID, ‘band’) ): ?> <strong>Band:</strong> <?php echo implode( $bands, ‘, ‘ ); ?><br /> <?php endif; ?> EDIT- another version of above, pluralizing the label depending on single or multiple meta values: <?php if( $bands = get_post_meta($post->ID, ‘band’) ): $label = … Read more