Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Code/process to get option dropdown menu selection to open page in WordPress with php?

Tried all kinds of plug-ins, widgets, but none will make menu that fits requirements of project so far.

Selections are page titles that are dynamically loaded from a table of address and other data. Based on previous selection of state, then city, then place, the next step is to open WordPress page from selected title, called place.

This is a normal option-select box:

<input type="submit" name="submit" value="place">

The selections are WordPress page titles. When submit is pressed, the issue is to go to page selected, a page for the selected business.

What I'm actually trying to do is produce a menu that can select among pages by state, city, and choose the place - the page belonging to that place. Eventually this will expand to country but right now the US. Each place has its own page. Tried a lot of plug ins and widgets and none has so far been up to this. I don't know beans about java so I went with php.

share|improve this question
    
What is your question? What have you tried? What didn’t work? Add your code to the question please. –  toscho Jan 2 '13 at 6:29
    
Question re-written. –  ED Chou III Jan 2 '13 at 13:10
    
You say the page titles are loaded from a non-WordPress table, but then you say they're WordPress page titles, which one is it? –  Milo Jan 2 '13 at 18:42
    
Both. They are WordPress page titles loaded from a non-WordPress table. –  ED Chou III Jan 2 '13 at 19:24
    
Essentially I'm needing to load the page by its title. These titles will match due to the pages having been created and titled originally from these lists. I can choose a state and get its list of cities which will give a list of businesses in that city, from which I can choose(This part of the select is called "place"). This is where the selection needs to open the page. Each business has its own page. The selection needs to take one to that page on submit. –  ED Chou III Jan 3 '13 at 1:00
add comment

1 Answer

Looks like not many folks do this. Anyway here's something that works for me to get drop-down select to go to WordPress page"

<?php
$my_title = $_POST['place'];
global $wpdb;
$mypost = $wpdb->get_row( "SELECT * FROM wp_posts WHERE post_title = '" . $my_title . "' " );
$permalink = get_permalink($mypost->ID);
echo "<a href=$permalink><BR>Click Here to Go to Selection</a>";
?>

"place" is the name of the select. Once the selection is made and submitted, this opens the page with the same name as selected. The names in the select box have to be the same as page names. If it can't find the page, you will get a 404, or whatever your item-not-found response is.

share|improve this answer
1  
Please do not use a second account to answer your own question. –  toscho Jan 7 '13 at 16:16
1  
two things- 1. never hardcode table names into queries, 2. WordPress has a function to fetch a post by title: get_page_by_title, no need for raw SQL –  Milo Jan 7 '13 at 16:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.