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.

What I am having trouble with is a dropdown box that I want to add to my sidebar. the blog will have more than one user so what I want for the dropdown to do is list all the different users by their display name and then once you click on one of the selected users to redirect you to that users bio page...

the problem is that the only thing linking the users to their bio pages is the title of the page which will be their full name... so now I have to figure out a way to get the page id based on its title (since in the dropdown you will select the user by their full name which will equal the page title)...

what I have been trying to do is tweak the wp_dropdown_users by adding stuff to the :

$output = "<select onChange='this.form.action=\"/wordpress/?page_id=\"
           +this.options[this.selectedIndex].text ; this.form.submit()'
           name='{$name}'{$id} class='$class'>\n";

now I am pretty sure I need a little php code to query the db or call a function instead of the this.options[this.selectedIndex].text, this code would, hopefully, return only the id of the page by its title... thus the url would be /wordpress/?page_id=(the id number returned)...

this is the function I found for getting the page id by its title:

 function get_page_by_title($page_title)
 {
    $page = get_page_by_title($page_title);
    // $page is the post array. To just retrieve the id
    $id = $page->ID;
    return $id;
 }

but I do not know the syntax well enough to implement it... would it be possible to call this function in this.form.action? is it even possible? any other way? any help would be appreciated and sorry if I didn't do something (research or explanation wise)

p.s. I am doing my blog on my computer as the host so I cant really link to it since its not live sorry

share|improve this question
add comment

migrated from stackoverflow.com Jul 2 '11 at 22:54

This question came from our site for professional and enthusiast programmers.

1 Answer

ok so i figured it out... i changed the select to

  <select onChange='this.form.submit()' name='page_id'{$id} class='$class'>

so that name passed in the url gets changed to ?page_id which i want since that is the format i am using (default wordpress format), and then i called my page_by_title function (btw i had to change the name of the get_page_by_title since it was the wp api name and it would otherwise just go into an infinite recursive loop XD) int the options like so

  <option value='".page_by_title($display)."'$_selected>" . esc_html($display) . "</option>

the value passed was the page id... i believe the form must use the get method for this to work

share|improve this answer
add comment

Your Answer

 
discard

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