Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
$40
Show Custom Post Titles Based On a Selected Custom Taxonomy
I have 1 custom taxonomy named "province" and 1 custom-post-type named "pizzerie".
I need the taxonomy items displayed in a drop-down.
When I select a taxonomy item the second dropdown must display and links all the titles of the custom-post-type items based on what taxonomy item is selected. And when I select a title It will open the relative custom-post. It is similar to State and Cities. When I select the State in a first dropodown the relative Cities will display in a second dropdown.
Best regards, Antonio
This question has been answered.
natspace | 06/30/12 at 12:43pm
Edit
Previous versions of this question:
07/01/12 at 6:36am
| 07/01/12 at 6:36am
| 07/01/12 at 6:39am
| 07/01/12 at 6:39am
| 07/01/12 at 6:43am
(20) Possible Answers Submitted...
See a chronological view of answers?
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
-

Last edited:
06/30/12
12:50pmDaniel Yoen says:try this :
<?php wp_dropdown_categories('taxonomy=custom_taxonomy_name'); ?>- 06/30/12 1:18pm
Daniel Yoen says:Depends on your previous Post, you need this :
<form role="search" method="get" id="searchform" action="<?php bloginfo('home'); ?>">
<div>
<input type="text" value="" name="s" id="s" />
<?php
function get_terms_dropdown($taxonomies, $args){
$myterms = get_terms($taxonomies, $args);
$optionname = "optionname";
$emptyvalue = "";
$output ="<select name='".$optionname."'><option selected='".$selected."' value='".$emptyvalue."'>Select a Category</option>'";
foreach($myterms as $term){
$term_taxonomy=$term->YOURTAXONOMY; //CHANGE ME
$term_slug=$term->slug;
$term_name =$term->name;
$link = $term_slug;
$output .="<option name='".$link."' value='".$link."'>".$term_name."</option>";
}
$output .="</select>";
return $output;
}
$taxonomies = array('YOURTAXONOMY');
$args = array('order'=>'ASC','hide_empty'=>true);
echo get_terms_dropdown($taxonomies, $args);
?>
<input type="submit" id="searchsubmit" value="Search" />
</div>
</form>
- 06/30/12 1:28pm
natspace says:Well I insert your:
<script type="text/javascript">
$(document).ready(function(){
$("#json_options").change(function(){
var json_option = $("#json_options").val();
$("#json_post").empty().append("<option>loading...</option>"); //show loading...
var json_url = "<?php echo get_template_directory_uri(); ?>/index-json.php?json_option=" + encodeURIComponent(json_option);
$.getJSON(json_url,function(data){
$("#json_post").empty(); //clear states selections
if(data==""){
$("#json_post").append("<option value=\"0\">No states found</option>");
}
else{
for(i=0; i<data.id.length; i++){
$("#json_post").append("<option value=\"" + data.id[i] + "\">" + data.name[i] + "</option>");
}
}
});
return false;
});});
</script>
<?php
function get_terms_dropdown($taxonomies, $args)
{
$myterms = get_terms($taxonomies, $args);
foreach ($myterms as $term)
{
$term_taxonomy = $term->taxonomy;
$term_slug = $term->slug;
$term_name = $term->name;
$link = $term_slug;
$output .= "<option value=" . $term_slug . ">" . $term_name . "</option>";
}
return $output;
}
$taxonomies = array('province'); // REPLACE WITH YOUR OWN TAXONOMY
$args = array('orderby' => 'count','hide_empty' => true);
?>
<select name="json_options" id="json_options">
<option value="0">Select here</option>
<?php echo get_terms_dropdown($taxonomies, $args); ?>
</select>
<select name="json_post" id="json_post"></select>
In my custom template and add your index-json.php in my theme directory.
The first dropdown works fine, infact It displays all my taxonomy values. But when I selec a taxonomy value the second dropdown doesn't display the relative custom-post titles.
- 06/30/12 1:18pm
-
Last edited:
06/30/12
1:19pmKailey Lampert says:I just tested this and it worked
function get_terms_dropdown() {
echo '<form class="searchcat" role="search" method="get" id="searchform" action="' . home_url() .'">';
echo'<div class="rowElem">';
echo'<input type="text" value="" name="s" id="s" placeholder="search here..." tabindex="1" />';
echo'<input type="submit" id="searchsubmit" value="Search" tabindex="2" />';
echo'</div></form>'; //form tag closes before <select>?
$taxonomies = array('pizzerie');//change Your_Texonomy to yours
$args = array('orderby'=>'count', 'hide_empty'=>true );
$myterms = get_terms( $taxonomies, $args );
$output = "<select>";
foreach($myterms as $term){
$term_taxonomy=$term->taxonomy;
$term_name =$term->name;
$link = get_term_link( $term, $term_taxonomy);
$output .= "<option value='{$link}'>{$term_name}</option>";
}
$output .= "</select>";
echo $output;
}
And could you clarify "nothing happens"? Does that really mean that nothing happens, or just that what you're expecting doesn't happen?Previous versions of this answer: 06/30/12 at 1:19pm
-

Last edited:
06/30/12
1:06pmArnav Joy says:change here
$taxonomies = array('pizzerie');//change Your_Texonomy to yours
to
$taxonomies = array('category');//change Your_Texonomy to yours
check if it is called now
- 06/30/12 1:13pm
Arnav Joy says:one more thing
change hide_empty to false as follows:-
$args = array('orderby'=>'count','hide_empty'=>false)
so new function will look like..
function get_terms_dropdown() {
echo '<form class="searchcat" role="search" method="get" id="searchform" action="' . get_bloginfo('url') .'">';
echo'<div class="rowElem">';
echo'<input type="text" value="" name="s" id="s" placeholder="search here..." tabindex="1" />';
$taxonomies = array('pizzerie');//change Your_Texonomy to yours
$args = array('orderby'=>'count','hide_empty'=>false);
echo'<input type="submit" id="searchsubmit" value="Search" tabindex="2" />';
echo'</div></form>';
$myterms = get_terms($taxonomies, $args);
$output ="<select>";
foreach($myterms as $term){
$root_url = get_bloginfo('url');
$term_taxonomy=$term->taxonomy;
$term_slug=$term->slug;
$term_name =$term->name;
$link = $root_url.'/'.$term_taxonomy.'/'.$term_slug;
$output .="<option value='".$link."'>".$term_name."</option>";
}
$output .="</select>";
echo ($output);
}
add_action('init', 'get_terms_dropdown');
- 06/30/12 1:13pm
-

Last edited:
07/01/12
12:53pm -

Last edited:
07/01/12
12:58pm -

Last edited:
07/01/12
3:59pm -

Last edited:
07/01/12
4:21pm -

Last edited:
07/02/12
3:10am -

Last edited:
07/02/12
3:28am -

Last edited:
07/02/12
4:33am -

Last edited:
07/02/12
4:49am -

Last edited:
07/02/12
4:50am -

Last edited:
07/02/12
4:53am -

Last edited:
07/02/12
5:11am -

Last edited:
07/02/12
5:22am -

Last edited:
07/02/12
5:38amoslemmonseste says: -

Last edited:
07/02/12
5:47am -

Last edited:
07/02/12
5:57am -

Last edited:
07/02/12
5:58am -

Last edited:
07/02/12
6:23am
This question has expired.
Lawrence Krubner had additional discourse to offer.
Gabriel Reguly, idt, Hai Bui, Arnav Joy, natspace voted on this question.
Current status of this question: Completed
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
