Problems:
The save works, but is only storing one of the options in the database after save.
Options not showing as selected after save.
The select fields:
<select id="exclude_page_from_cookies" name="exclude_page_from_cookies[]" multiple="multiple">
<?php
$pages = get_pages();
foreach ( $pages as $page ) {
$title = $page->post_title;
$id = $page->id;
?>
<option id="<?php echo $id; ?>" value="<?php echo $title ?>" <?php selected( $title ); ?> >
<?php echo $title;?>
</option>
<?php
}
?>
</select>
The save function:
if ( isset( $_POST['exclude_page_from_cookies'] ) ) {
foreach( $_POST['exclude_page_from_cookies'] as $exclude_page ) {
echo $exclude_page;
update_option( 'exclude_page_from_cookies', $exclude_page ) ;
}
}
I'm assuming selected() is a wordpress function?
I guess your line should look like this:
<option <?php selected( $title ); ?> value="<?php echo $title ?>">
(with selected outside of value="")
EDIT
as per #comfreak:
foreach($_POST['exclude_page_from_cookies'] as $exclude_page ){
update_option('exclude_page_from_cookies',$exclude_page);
}
Related
I have a select box, which allows you to navigate between parent pages and their children, they are given a specific order, in order to display them in a certain way on the website.
I believe that the line of code that interest you is perhaps this one
$children = get_pages("title_li=&child_of=" . $parent . "&echo=0");
The full code is below. You can see that the order of the pages on the site is different than the order of the pages in the select menu, that is because wordpress sorts per order, my pages are sorted alphabetically. How to sort them by order, so that what you see on the website matches the select box?
<?php
// determine parent of current page
if ($post->post_parent)
{
$ancestors = get_post_ancestors($post->ID);
$parent = $ancestors[count($ancestors) - 1];
}
else
{
$parent = $post->ID;
}
$children = get_pages("title_li=&child_of=" . $parent . "&echo=0");
?>
<div id="info-select-wrap" class="single-france-select">
<select id="info-select"class="fr-select" >
<?php
if (get_the_ID() == $parent->ID): ?>
<option value="<?php
echo get_the_permalink($parent->ID); ?>" selected> <?php
echo get_the_title($parent->ID); ?></option>
<?php
else: ?>
<option value="<?php
echo get_the_permalink($parent); ?>"> <?php
echo get_the_title($parent); ?></option>
<?php
endif;
foreach($children as $child):
if (has_children($child))
{
if (get_the_ID() == $child->ID)
{ ?>
<option value="<?php
echo get_the_permalink($child->ID); ?>" selected> <?php
echo get_the_title($child->ID); ?></option>
<?php
}
else
{ ?>
<option value="<?php
echo get_the_permalink($child->ID); ?>"> <?php
echo get_the_title($child->ID); ?></option>
<?php
}
}
else
{
if (get_the_ID() == $child->ID)
{ ?>
<option value="<?php
echo get_the_permalink($child->ID); ?>" selected> <?php
echo get_the_title($child->ID); ?></option>
<?php
}
else
{ ?>
<option value="<?php
echo get_the_permalink($child->ID); ?>"> <?php
echo get_the_title($child->ID); ?></option>
<?php
}
}
endforeach; ?>
</select>
</div>
I tried
$children = get_pages("title_li=&child_of=" . $parent . "&echo=0&orderby='menu_order'&order='ASC'");
Didn't solve it.
Issue solved by adding sort_column=menu_order
$children = get_pages("title_li=&child_of=" . $parent . "&echo=0&sort_column=menu_order");
Just a quick note, &echo=0 is useless, you can remove it.
I'm new to WordPress and a very new to "shopp plugin",
I want to select box that displays shipping method
shopp('shipping', 'option-menu', 'difference=on');
This doesn't work. Please tell me in details about how to fetch this shipping method data using above code and where to look after the code for further changes to get the select box with details comes by OrderAmount-0, ItemQuantity-0 filling from [shipping menu] present in [system] side menu.
Try this code:
<?php if ( shopp('shipping', 'has-options') ): ?>
<?php while ( shopp('shipping','options')):
$selected = '';
if ( shopp('shipping','option-selected') )
$selected = ' selected="selected"';
$value = shopp('shipping','get-option-slug');
$name = shopp('shipping','get-option-name');
$cost = shopp('shipping','get-option-cost);
$delivery = shopp('shipping', 'get-option-delivery');
$label = $name.' &mdash '.$cost.' '.$delivery;
?>
<select name="shipmethod" class="shopp shipmethod">
<option value="<?php echo $value; ?>"<?php echo $selected; ?> ><?php echo $label; ?></option>
</select>
<?php endwhile; ?>
<?php endif; ?>
I have this code from the interwebs about how to duplicate a field in a form.
Now the problem is that this form is a text field, but I would like to have a drop down list with all pages from my website.
This would be easy if it only was in PHP since I don't know how to write jQuery
So is there anybody out there who is kind enough and willing to combine these two codes for me:
JQuery:
<script type="text/javascript">
var fieldname = <?php echo json_encode( $this->get_field_name('stream_sources') ) ?>;
var fieldnum = <?php echo json_encode( $stream_counter-1 ) ?>;
jQuery(function($) {
var count = fieldnum;
$('.<?php echo $this->get_field_id( 'add_field' );?>').click(function() {
$("#<?php echo $this->get_field_id( 'field_clone' );?>").append("<p><input type='text' name='"+fieldname+"["+(count+1)+"][title] value='' class='widefat sourc"+(count+1)+"'><span class='remove-field button button-primary button-large'>Verwijderen</span></p>");
count++;
});
$(".remove-field").live('click', function() {
$(this).parent().remove();
});
});
</script>
With this PHP:
<select name="meta-url-1" id="meta-url-1"><?php
global $post;
$args = array( 'numberposts' => -1);
$posts = get_pages($args);
echo '<option value="#"></option>';
foreach( $posts as $post ) : setup_postdata($post); ?>
<option value="<?php echo $post->post_name; ?>"><?php the_title(); ?></option>
<?php endforeach; ?>
</select>
Notice that the PHP is how I would write it. But I need to have the drop down in a repeatable field.
Hope this is possible && anyone would help.
M.
Your code is
<option value="<?php echo $post->post_name; ?>"><?php the_title(); ?></option>
In this case the value you are assigning in option will not repeat. You will need to assign a unique value to each option.
I suggest you to use a number variable to assign value.
Try below code:
<select name="meta-url-1" id="meta-url-1"><?php
global $post;
$args = array( 'numberposts' => -1);
$posts = get_pages($args);
$i = 0;
echo '<option value="#"></option>';
foreach( $posts as $post ) : setup_postdata($post); ?>
<option value="<?php echo $i++; ?>"><?php the_title(); ?></option>
<?php endforeach; ?>
</select>
Hi I'm trying to create a function to show a list of posts in my admin menu of wordpress but because I'm calling the function a few times on the same page I needed to add some extra statements but it breaks the output and I don't know why
Here is my current code that outputs the basics:
function test() {
// The Query
query_posts( array ('posts_per_page' => -1 ) );
// The Loop
while ( have_posts() ) : the_post();
?>
<option value="<?php the_permalink() ?>"><?php the_title(); ?></option>
<?php endwhile;
// Reset Query
wp_reset_query();
}
Output code:
<select>
<?php test(); ?>
</select>
Returned Output:
<select>
<option value="http://website/posttitle1">POST TITLE 1</option>
<option value="http://website/posttitle2">POST TITLE 2</option>
<option value="http://website/posttitle3">POST TITLE 3</option>
</select>
But I need to add a select option on like this:
function test($select) {
// The Query
query_posts( array ('posts_per_page' => -1 ) );
// The Loop
while ( have_posts() ) : the_post();
if ($select == the_permalink()) { $selected = " selected"; }
?>
<option value="<?php the_permalink() ?>"><?php the_title(); ?></option><?php echo "\n"; ?>
<?php endwhile;
// Reset Query
wp_reset_query();
}
Output code:
<select>
<?php test("..GET Permalink from Database.."); ?>
</select>
But then this is my output:
<select>
http://website/posttitle1<option value="http://website/posttitle1">POST TITLE 1</option>
http://website/posttitle2<option value="http://website/posttitle2">POST TITLE 2</option>
http://website/posttitle3<option value="http://website/posttitle2">POST TITLE 3</option>
</select>
I dont understand?
the_permalink() print the value and get_permalink() returns the value.
Try this.
Change the following line
if($select == the_permalink()) { $selected = " selected"; }
to
if ($select == get_permalink()) { $selected = " selected"; }
And this line to
<option value="<?php the_permalink() ?>"><?php the_title(); ?></option><?php echo "\n"; ?>
this
<option value="<?php echo get_permalink() ?>"><?php echo get_the_title(); ?></option><?php echo "\n"; ?>
I have associated a bundle product sku with simple product.
Now I am trying to fetch bundled product options.
$selectionCollection = $bundled_product->getTypeInstance(true)->getSelectionsCollection(
$bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product
I have used the above code but it returns me all simple product under bundled.
But i want the array of options.
From options i want array of selections so that i can iterate and create dropdown for every bundled option
I looked into the core select.phtml
<select onchange="bundle.changeSelection(this)" id="bundle-option-<?php echo $_option->getId() ?>" name="bundle_option[<?php echo $_option->getId() ?>]" class="bundle-option-<?php echo $_option->getId() ?><?php if ($_option->getRequired()) echo ' required-entry' ?> bundle-option-select change-container-classname">
<option value=""><?php echo $this->__('Choose a option') ?></option>
<?php foreach ($_selections as $_selection): ?>
<option value="<?php echo $_selection->getSelectionId() ?>"<?php if ($this->_isSelected($_selection)) echo ' selected="selected"' ?><?php if (!$_selection->isSaleable()) echo ' disabled="disabled"' ?>><?php echo $this->getSelectionTitlePrice($_selection, false) ?></option>
<?php endforeach; ?>
</select>
I want to replicate similar thing on view.phtml. However i am not able access those methods.
Does anyone has idea how do i do that.
$optionCollection = $product->getTypeInstance()->getOptionsCollection();
$selectionCollection = $product->getTypeInstance()->getSelectionsCollection($product->getTypeInstance()->getOptionsIds());
$options = $optionCollection->appendSelections($selectionCollection);
foreach( $options as $option )
{
$_selections = $option->getSelections();
foreach( $_selections as $selection )
{
echo $selection->getName();
}
}