Title: PHP Code in Select box
Last modified: August 19, 2016

---

# PHP Code in Select box

 *  [BrenFM](https://wordpress.org/support/users/brenfm/)
 * (@brenfm)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/php-code-in-select-box/)
 * Got a fresh install – and this about the 5th time I’ve used this plugin in a 
   commercial project. I LOVE it so far. HOWEVER!
 * I’ve got a select custom field (dropdown) that is looking up page names & IDs
   using the following code:
 *     ```
       //product pages
       global $wpdb;
       $items = $wpdb->get_results("SELECT ID,post_title
       FROM $wpdb->posts
       where post_type = 'page'
       and post_status = 'publish'
       order by post_title ASC");
       $i = 0;
       foreach ($items as $item) {
       	$values[$i] = $item->ID;
       	$valueLabel[$i] = $item->post_title;
       	$i++;
       }
       ```
   
 * What appears to be happening is that select box is being populated with the value
   of each option being set to the ID (as expected) but the DISPLAY (label) is ALSO
   being set to the ID (not the post_title). I can alter it so it uses the TITLE
   for both, but this is not ideal – especially if the page names change. I really
   need to USE the ID but display the Title. This issue was prevalent yesterday 
   when using 3.1.1 (before upgrading to 3.1.2)
 * I’m using CFT v1.8.6 on this site. Also using 1.8.3 on an older site with WP3.1
   which works sweet, so not sure if it’s WP or CFT that is causing this.
 * Any ideas/thoughts/similar experiences?

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

 *  Thread Starter [BrenFM](https://wordpress.org/support/users/brenfm/)
 * (@brenfm)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/php-code-in-select-box/#post-2052286)
 * HAH! Just downgraded to v1.8.3 on this install and it works sweet again. DEFINITELY
   an issue with this plugin. Please, please, please review this bug.
 *  [memm0](https://wordpress.org/support/users/memm0/)
 * (@memm0)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/php-code-in-select-box/#post-2052377)
 * AGREE
 * Using the following code to post content by page_title
 *     ```
       <?php
       function wt_get_ID_by_page_name($page_title)
       {
       	global $wpdb;
       	$page_title_id = $wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE post_title = '%".$page_title."%' AND post_status='publish'");
       	return $page_title_id;
       }
       ?>
       ```
   
 * Worked fine yesterday. But I upgraded to 3.1.2 today and now it’s without function.

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

The topic ‘PHP Code in Select box’ is closed to new replies.

 * ![](https://ps.w.org/custom-field-template/assets/icon-256x256.png?rev=1966286)
 * [Custom Field Template](https://wordpress.org/plugins/custom-field-template/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/custom-field-template/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/custom-field-template/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-field-template/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-field-template/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-field-template/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [memm0](https://wordpress.org/support/users/memm0/)
 * Last activity: [15 years, 1 month ago](https://wordpress.org/support/topic/php-code-in-select-box/#post-2052377)
 * Status: not resolved