Please Help me! I want to show the Name of agent, but unfortunately, I get value instead of Agent name. I am new to PHP. This the code. What I do, i use this code.
<?php
if( !empty( $wpc_agents ) ) {
$agent = $wpcargo->get_shipment_agent( $post->ID );
?>
<select name="agent_fields">
<option value=""><?php _e('-- Select One --', 'wpcargo' ); ?></option>
<?php
foreach ($wpc_agents as $val) {
?>
<option value="<?php _e(sanitize_text_field($val->ID)); ?>" <?php selected( $agent, $val->ID ); ?> ><?php _e(sanitize_text_field($val->display_name)); ?></option>
<?php
}
?></select><?php
}
?>
And display value with this code
$agent = get_post_meta($shipment_id,
'agent_fields', true);
<div class="col-4">
<p class="label">
<?php _e('Agent Name', 'wpcargo'); ?>
</p>
<p class="label-info"><?php echo $agent; ?></p>
</div>
But this $agent giving me the ID of the agent instead of his name :(
Thanks in advance!
Related
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);
}
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 am using onestepcheckout in Magento. I have added in some extra flat rates and I am using two of them. I want to be able to only show one of the flat rates depending on the subtotal of the cart.
I have got the subtotal into a variable but the code has a foreach through each shipping method available so I need a way to say if $total is over 500 only show the second shipping method, if the total is under 500 only show the first shipping method.
<?php $total = Mage::getSingleton('checkout/session')->getQuote()->getSubtotal(); ?>
<?php foreach ($_shippingRateGroups as $code => $_rates): ?>
<dd><?php echo $this->getCarrierName($code) ?></dd>
<?php foreach ($_rates as $_rate): ?>
<dt style="margin-bottom: 5px;">
<?php if ($_rate->getErrorMessage()): ?>
<ul class="messages"><li class="error-msg"><ul><li><?php echo $_rate->getErrorMessage() ?></li></ul></li></ul>
<?php else: ?>
<input name="shipping_method" type="radio" class="validate-one-required-by-name" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> />
<label for="s_method_<?php echo $_rate->getCode() ?>"><!--<b><?php echo $this->getCarrierName($code) ?>:</b>--> <?php echo $_rate->getMethodTitle() ?>
<strong>
<?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
<?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
<?php echo $_excl; ?>
<?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
(<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
<?php endif; ?>
</strong>
</label>
<?php endif ?>
</dt>
<?php endforeach; ?>
<?php endforeach; ?>
Just do ...
//first method here by default
if($total>500){
//second method here
}
Something tells me you already know how to do this though
I can't decipher, what the first and second method are in your code, otherwise I would've posted a more complete code
I am using a script that runs on the YII framework...
I have this select box that lets a user view content based on their country. But right now, when a user selects their country, after the selection, it just shows the country name...
And what I want is, after a user selected their country... it must still show the select box, but have the selected country at the top of the list.
I have tried so many things but I'm still new to this this.
<?php if ( $_country == '' ) { ?>
<select onchange="changeCountry(this)" name="country" id="country">
<?php if ( count ($c) != 0 ) { ?>
<?php if ( $_country == NULL ) ?>
<?php foreach ($c as $id => $val) { ?>
<option<?php if ($id == $countryId) {?> selected="selected"<?php } ?> value="<?php echo mbCoreFunctions::to_seo_ad_name ($val, $id) ?>"><?php echo $val; ?></option>
<?php } ?>
<?php } ?>
</select>
<?php } else { ?>
<span class="countryName"><?php echo $countryName; ?></span>
<?php } ?>
I didn't try but following should work
<select onchange="changeCountry(this)" name="country" id="country">
<?php foreach ($c as $id => $val) { ?>
<option<?php if ($id == $countryId) {?> selected="selected"<?php } ?> value="<?php echo mbCoreFunctions::to_seo_ad_name ($val, $id) ?>"><?php echo $val; ?></option>
<?php } ?>
</select>
I am trying to extend product order
report and add one Attribute of
product brand and put into
grid.phtml.
when i select brand and click on
refresh button.
report will not display brand wise
searching what can i do?
product order report image link
Visit
http://imageshack.us/photo/my-images/405/productorder.jpg/
grid.phtm Code
<?php
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')
->setCodeFilter('brand')
->getFirstItem();
$attributeOptions = $attributeInfo->getSource()->getAllOptions(false);
?>
</div>
--><div class="f-left">
<?php echo $this->__('Brand') ?>:
<select name="brand" id="brand" style="width:6em;">
<?php foreach ($attributeOptions as $_value=>$_label): ?>
<option value="<?php echo $_value ?>" <?php if($this->getFilter('brand')==$_value): ?> selected<?php endif; ?>><?php echo $_label['label'] ?></option>
<?php //error_log("Lable".print_r($_label,TRUE));?>
<?php endforeach; ?>
</select>
</div>