• So… I am creating my own WP theme, which includes an admin page that I custom developed myself to manage the theme. I am having an issue with trying to use a <select> box to choose the “Feature” post on the site. I am using the following code to grab the last 50 site posts and display them in a <select> box:

    <select name="choose-post-dropdown">
        <option value=""><?php echo attribute_escape(__('Select a Post (Try to be more recent)')); ?></option>
        <?php wp_get_archives('type=postbypost&format=option&show_post_count=0&limit=50'); ?>
    </select>

    You can see these images to get an idea of what the code does for my admin page: Here and Here

    So, now I want, when I chose a post, the <select> box to update it’s value with the selected posts ID… because ultimately I am going to be grabbing the value like this:

    <input type="hidden" name="page_options" value="dd_mainfeature_post_id," />

    And then displaying in my theme like this…

    <?php echo get_option("dd_mainfeature_post_id"); ?>

    Can anyone help with my problem??

    thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • You don’t wanna use wp_get_archives() for this, but get_posts(). I’ve made a function like that, and used this code:

    <select name="featuredpost">
    	<option value="">Choose Post</option>
    	<?php
    	$pages = get_posts('numberposts=10');
    	foreach ($pages as $pagg) {
    		if($current==$pagg->ID) { $selected = ' selected'; } else { $selected = ''; }
    		$option = '<option value="'.($pagg->ID).'"'.$selected.'>';
    		$option .= $pagg->post_title;
    		$option .= '</option>';
    		echo $option;
    	}
    	?>
    </select>
    Thread Starter deziiner

    (@deziiner)

    Hey! Thanks that worked perfectly for what I needed; you can see below how I customized it to do what I need. But I have one problem: I have sections in my theme for one main feature, and 3 secondary posts. I’ve got the code for the main feature post working, but when I copy the code (and change the IDs, names, etc.) to the other 3 places where I need it, the code only works for the last chosen <select> box. Here’s the code I’m using…

    <p>
                    <label for="dd_mainfeature_post_id"><strong>Choose the <strong>main feature</strong> post.</strong></label><br />
                    <select id="dd_mainfeature_post_id" name="dd_mainfeature_post_id">
                        <option value="">
                        <?php if(get_option('dd_mainfeature_post_id')) : ?><?php $showpost = new WP_query(); $showpost->query('p=' . get_option('dd_mainfeature_post_id')); ?><?php while ($showpost->have_posts()) : $showpost->the_post(); ?><?php the_title(); ?><?php endwhile; ?><?php else : echo 'Choose a Post! (Try to stay more recent)'; endif; ?>
                        </option>
                        <?php
                        $pages = get_posts('numberposts=40');
                        foreach ($pages as $pagg) {
                            $mfoption = '<option value="'.($pagg->ID).'"'.$selected.'>';
                            $mfoption .= $pagg->post_title;
                            $mfoption .= '</option>';
                            echo $mfoption;
                        }
                        ?>
                    </select>
                </p>

    Think you or anyone could help with this?

    🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Trying to wp_get_archives to display the post ID in a <select> box!’ is closed to new replies.