Title: text value to php
Last modified: January 21, 2017

---

# text value to php

 *  [apollo789](https://wordpress.org/support/users/apollo789/)
 * (@apollo789)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/text-value-to-php/)
 * This not working out for me. Any tips or example to make it work? post args =
   array($tags) didnt get value correctly.
 *     ```
       <h6>seal</h6>
       <h6>mark</h6>
       <?php
           $tags = "<script>document.write(h6);</script>"; 
   
       $args = array( 
           'post_type' => 'Rune', 
           'posts_per_page' => -1,
           'tag' => $tags,
   
       );
       $lastposts = get_posts( $args );
   
       foreach ( $lastposts as $post ) :
         setup_postdata( $post ); ?>
       	<?php the_content(); ?>
       <?php endforeach; 
       wp_reset_postdata(); 
       ?>
       ```
   

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/text-value-to-php/#post-8682304)
 * Using javascript to generate a tag argument makes no sense. Javascript only executes
   in a browser. PHP executes server side long before it gets to a browser. Is the
   intent in you example that “seal” and “mark” are to become tag arguments? Or 
   is it seal OR mark? Then the tag argument has to be either “seal+mark” or “seal,
   mark” respectively. These values can be assigned to $tags before the HTML content
   is output. Once HTML is output it’s gone, you can’t do anything with it.
 * Anytime you use setup_postdata( $post ), you need to ensure `global $post;` is
   declared somewhere within scope of your code.
 * Post type arguments take slugs as arguments not presentation names, so it’s probably‘
   rune’ and not ‘Rune’. Sometimes letter case does not matter, other times it does.
   It’s best to assume it always matters.
 * You don’t need <?php ?> tags for every line if there is no intervening HTML. 
   It doesn’t hurt, but it’s not necessary and makes for messy, inefficient code.
 *  Thread Starter [apollo789](https://wordpress.org/support/users/apollo789/)
 * (@apollo789)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/text-value-to-php/#post-8683604)
 * I want transfer value from created meta box, selected element go loop as a $tags
   
   [Link Code](https://gist.github.com/anonymous/1d67f2a85cecaa867b0ccf1bc8f4f13c)
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/text-value-to-php/#post-8685203)
 * You need to get the selected value from where ever it’s stored in the DB. The
   metabox outputs the form field, some other code needs to save the selected field
   somewhere.
 * In a similar vein, $options[“foo”] will not affect which field is selected because
   it is never assigned the saved value. The saved value is typically whatever the
   selected option value is, but you are determining selection on an integer while
   the option values are strings.
 *  Thread Starter [apollo789](https://wordpress.org/support/users/apollo789/)
 * (@apollo789)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/text-value-to-php/#post-8688384)
 * I was looking, but i couldnt find. I have 4options in metabox that I wanted. 
   But i cant save, getting error. I want fix this and add that saved options go
   to page-templates! Could u help with this?
    [Code Metabox](https://gist.github.com/anonymous/e006d38bf3ae7cd386a4c8987ce93a49)
    -  This reply was modified 9 years, 4 months ago by [apollo789](https://wordpress.org/support/users/apollo789/).
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/text-value-to-php/#post-8689796)
 * You should save the selected values through the rune_save() function. Where should
   the selection be saved? It can be anywhere in the DB. If the selection is related
   to the post being saved, post meta makes sense, so update_post_meta(() would 
   be correct, but the parameters currently used in your code are undefined. Don’t
   rely on the global $post, it may not have the values you think it does.
 * I don’t know what meta key you want to use, I’ll use “apo_runes”. It’s a good
   idea to prefix meta names with something unique in order to not conflict with
   other plugins. You can save the selected tag with this:
    `update_post_meta( $
   post_id, 'apo_runes', $_POST['runeselect'] );`
 * Note that this is a terrible example because we should never put user input directly
   into the DB. The value in $_POST actually needs validation and sanitation. What
   I’ve presented will suffice temporarily, but you need to implement proper security
   before going live.
 * When you output the field’s options, you can get the currently saved value if
   it exists with get_post_meta() and use it in the selected() function so that 
   the previously saved option is preselected for the user. This part is optional.
   Without this, the first option is always selected.
 * You can also use get_post_meta() anywhere on any template to get the saved value.
   You only need the associated post ID. If you are in the loop, get_the_ID() will
   return the current post ID.
 *  Thread Starter [apollo789](https://wordpress.org/support/users/apollo789/)
 * (@apollo789)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/text-value-to-php/#post-8710268)
 * almost working. How to put $meta to <options> now? How to put $meta in to page-
   template without using get_post_meta($post->ID, ‘apo_runes’, true);?
    [Code](https://gist.github.com/anonymous/112abafc93a445f39e5491c013f14bb7)
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/text-value-to-php/#post-8710637)
 * When you use the selected() function, you want to compare the current option 
   value with a previously saved value. If there’s a match, selected() will output
   the “selected” option attribute so that option is the one displayed by default
   on the page. The dropdown is displayed when you call skillbox_callback( get_the_ID()).
   The option represented by $meta should be displayed in the dropdown.
 * You cannot use $meta in the template without calling get_post_meta() again because
   it is local to your function. That’s how PHP works. You’d have to declare it 
   as global within your function and anywhere it is to be used in order to use 
   it outside the function. As a global, $meta is a poor name, it could easily clash
   with other variables using the same name. You should prefix it to use it globally,
   for example `global $apo_meta;`.
 *  Thread Starter [apollo789](https://wordpress.org/support/users/apollo789/)
 * (@apollo789)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/text-value-to-php/#post-8710848)
 * thanks a lot
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/text-value-to-php/#post-8713064)
 * Sure, no problem 🙂
 * Hey, I just had a thought. A little unconventional, and it may not work for you,
   depending where you want to use $meta on the template. The skillbox_callback()
   is referred to as a “template tag” because it outputs content and is intended
   for use on templates. Template tags normally do not return values, but they could.
   You could return the $meta value for subsequent use on the template even though
   the main purpose is to output a dropdown field.
 * Make the last line of the function this: `return $meta;`
 * Then call your function on the template, where you want the dropdown to occur,
   like so:
    `<?php $meta = skillbox_callback( get_the_ID()); ?>`
 * After this point in the template, you can now use $meta as desired without declaring
   it global. If you needed it before this point, then this scheme will not work.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘text value to php’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 9 replies
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [9 years, 4 months ago](https://wordpress.org/support/topic/text-value-to-php/#post-8713064)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
