I am using the post to display attorney verdicts and case details.  The post title is the verdict amount entered as a string. (no $ "," or ".")  I am formatting the title using PHP number format:  EX: User enters 360137 in the post title.     $number = get_the_title();      $ammount = number_format($number);      echo '&lt;h1&gt;$'. $ammount . '&lt;/h3&gt;';  Returns $360,137   This is working as expected.  Using get_posts() I can 'orderby' => 'title' and 'order' => 'DESC' or 'ASC'    $args = array(  'category' =&gt; 64,  'orderby' =&gt; 'title',  'order' =&gt; 'DESC' );   $myposts = get_posts( $args );  foreach ( $myposts as $post ) : setup_postdata( $post );   While this is working it does not recognize the length of the value. For example it will display 30,000 before 2,100,000. How do I get this list sorted by ASC or DESC AND by string length?  I want to show the largest verdicts first.  9,000,000  2,100,000  90,00  3,000
122344
I have post titles which begin with a price, eg: $199,900 - 123 Street. I am using the code below, and I'm unable to get the order by title ascending to work properly. Any suggestions please.  &lt;?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array(  'cat' =&gt;21,  'posts_per_page' =&gt; 999999,  'paged' =&gt; $paged,  'orderby' =&gt; 'title',  'order' =&gt; 'ASC',  ); $the_query = new WP_Query($args); ?&gt; &lt;div id="listings"&gt;  &lt;?php if ($the_query-&gt;have_posts()) : ?&gt;  &lt;?php while ($the_query-&gt;have_posts()): $the_query-&gt;the_post(); ?&gt;         &lt;div &lt;?php post_class() ?&gt; id="post-&lt;?php the_ID(); ?&gt;"&gt;             &lt;div class="title1 active_listing"&gt;                 &lt;?php                 if (in_category('6')) {                 the_title();                 } else {                 ?&gt;                  &lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;                 &lt;?php                 }                 ?&gt;             &lt;/div&gt;                  &lt;div class="alignleft thumb"&gt;&lt;?php the_post_thumbnail('thumbnail'); ?&gt; &lt;br /&gt; &lt;/div&gt;         &lt;div class="content"&gt;&lt;?php the_excerpt(); ?&gt; &lt;/div&gt;                  &lt;?php                 if (in_category('6')) {                 ?&gt; &lt;br /&gt;                 &lt;?php                 } else {                 ?&gt;  &lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark"&gt; View Details&lt;/a&gt;  &lt;br /&gt;                 &lt;?php                 }                 ?&gt;          &lt;/div&gt;      &lt;?php endwhile; wp_reset_postdata();?&gt;  &lt;?php else : ?&gt;      &lt;h2 class="center"&gt;Not Found&lt;/h2&gt;     &lt;p class="center"&gt;Sorry, but you are looking for something that isn't here.&lt;/p&gt;     &lt;?php get_search_form(); ?&gt;  &lt;?php endif; ?&gt;  &lt;/div&gt;
118444
i need comma in between my number  eg- 1000 --> 1,000  i m attaching the controller and vf page for this  public List&lt;BarData&gt; getOpportunityTarget(){     Integer CurrentMonth = Date.Today().Month();     Decimal total = 0.0;      TargetList = new List&lt;BarData&gt;();     if(MonthlyTargetMap.get(currentMonth) != null){         if(OpportunityList.size()&gt;0){                for(Opportunity objOpportunity : OpportunityList){                 if(objOpportunity.StageName == 'Approved' &amp;&amp; objOpportunity.Amount != null &amp;&amp; objOpportunity.closeDate.Month() == CurrentMonth){                     total += objOpportunity.Amount;                 }             }             TargetList.add(new BarData('Closed',total.setScale(0)));                     TargetList.add(new BarData('Target',MonthlyTargetMap.get(currentMonth).setScale(0)));                     }else{             TargetList.add(new BarData('Closed',0));                     TargetList.add(new BarData('Target',MonthlyTargetMap.get(currentMonth).setScale(0)));                     }     }                                         return TargetList;          Vf Page  &lt;div class="sections" &gt;                                    &lt;div class="graph-section"&gt;                                &lt;h2 align="center"&gt;Closed v/s Running Target &lt;/h2&gt;&lt;br/&gt;&lt;br/&gt;          &lt;apex:chart height="300" width="400" data="{!OpportunityTarget}"&gt;             &lt;apex:axis type="Numeric" position="left" fields="data" grid="true" minimum="0" /&gt;             &lt;apex:axis type="Category" position="bottom" fields="name"&gt;                 &lt;apex:chartLabel rotate="315" font="bold 13px Helvetica"/&gt;             &lt;/apex:axis&gt;             &lt;apex:barSeries orientation="vertical" axis="left" xField="name" yField="data" colorSet="#99ccff"&gt;                 &lt;apex:chartTips height="20" width="150" /&gt;                 &lt;apex:chartLabel field="data" display="outside" orientation="horizontal" font="bold 12px Helvetica" /&gt;                                                 &lt;/apex:barSeries&gt;         &lt;/apex:chart&gt;                                                 &lt;/div&gt; &lt;/div&gt;
43371
PHP has the habit of evaluating (int)0 and (string)"0" as empty when using the empty() function. This can have unintended results if you expect numerical or string values of 0. How can I "fix" it to only return true to empty objects, arrays, strings, etc?
110834
I have an archive page showing all blog posts (in a specific category). With a growing number of posts, I want to separate these by publish year. For example (simplified), I'd like the following:  2012   post post post   2011   post    I'm testing this system by changing my oldest post's publish date to mid-2011. Currently the structure appears to be mostly working, but all posts are showing up under 2012, and none under 2011, despite the oldest post's publish date being set to 2011. To illustrate, I'm getting this:  2012   post post post post (2011 post)   2011    I'm using the code below (some extra stuff has been removed to simplify, but it doesn't affect the result). Can anyone see why the old post is showing up under 2012 and not inside the 2011 &lt;ul&gt;? Thanks for your help.  &lt;?php global $query_string; query_posts($query_string . '&amp;posts_per_page=-1'); // Show all posts ?&gt; &lt;?php if (have_posts() { if (is_category('210')) { ?&gt; &lt;div class="archive-posts-box"&gt;     &lt;?php $firstyear = '2011';     $currentyear = date('Y');     $postyear = get_the_time('Y', $post-&gt;ID);     for ($i = $currentyear; $i &gt;= $firstyear; $i--) { ?&gt;             &lt;h4&gt;&lt;?php echo $i ?&gt;&lt;/h4&gt;             &lt;ul class="archive-posts"&gt;             &lt;?php while (have_posts() &amp;&amp; $postyear == $i) {                 the_post(); ?&gt;                 &lt;li&gt;&lt;span class="archive-post-title"&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/span&gt;&lt;span class="archive-post-date"&gt;&lt;?php the_time(get_option('date_format')); ?&gt;&lt;/span&gt;&lt;/li&gt;             &lt;?php } // end while ?&gt;             &lt;/ul&gt;         &lt;?php } // end for ?&gt;         &lt;/div&gt;&lt;!-- .archive-posts-box --&gt; &lt;?php } // end if (category) } // end if (have_posts) wp_reset_query() ?&gt;
68975
When asking a question the title textbox allows 300 characters max. But If I try to post such a long question title I get an error after hitting the post button:     title too long; maximum length 150   Could you please sync that?!
50683
I have a code snippet written in PHP that pulls a block of text from a database and sends it out to a widget on a webpage.  The original block of text can be a lengthy article or a short sentence or two; but for this widget I can't display more than, say, 200 characters.  I could use substr() to chop off the text at 200 chars, but the result would be cutting off in the middle of words-- what I really want is to chop the text at the end of the last word before 200 chars.
71324
I want to get records from custom object sort by a field as number. The field I want to sort is string type. Is there any way to do that? I am storing result in list, is there a way to sort list based on the string field but sort it as number?
78018
I am using the following code to output a list of items in my 'documents' Custom Post type by Year and Month.  &lt;ul&gt; &lt;?php $post_type = 'documents'; global $wpdb; /**/ $years = $wpdb-&gt;get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb-&gt;posts WHERE post_status = 'publish' AND post_type = '".$post_type."' ORDER BY post_date DESC"); foreach($years as $year) : $years_count = $wpdb-&gt;get_var( $wpdb-&gt;prepare( "SELECT COUNT(*) FROM $wpdb-&gt;posts WHERE post_status = 'publish' AND post_type = '".$post_type."' AND YEAR(post_date) = ".$year.";" ) ); ?&gt; &lt;li class="year"&gt;&lt;?php echo $year; ?&gt; (&lt;?php echo $years_count; ?&gt; Posts)     &lt;ul&gt;     &lt;? $months = $wpdb-&gt;get_col("SELECT DISTINCT MONTH(post_date) FROM $wpdb-&gt;posts WHERE post_status = 'publish' AND post_type = '".$post_type."' AND YEAR(post_date) = '".$year."' ORDER BY post_date DESC");     foreach($months as $month) :     $months_count = $wpdb-&gt;get_var( $wpdb-&gt;prepare( "SELECT COUNT(*) FROM $wpdb-&gt;posts WHERE post_status = 'publish' AND post_type = '".$post_type."' AND YEAR(post_date) = ".$year." and MONTH(post_date) = ".$month.";" ) );     ?&gt;         &lt;li class="month"&gt;&gt;         &lt;a href="&lt;?php echo get_month_link($year, $month)."?post_type=".$post_type; ?&gt;"&gt;&lt;?php echo date( 'F', mktime(0, 0, 0, $month) );?&gt;&lt;/a&gt; (&lt;?php echo $months_count; ?&gt; Posts)          &lt;?php  $theids = $wpdb-&gt;get_results("SELECT ID, post_title, post_date FROM $wpdb-&gt;posts WHERE post_type = '".$post_type."' AND post_status = 'publish' AND YEAR(post_date) = ".$year." and MONTH(post_date) = ".$month.";");                 foreach ($theids as $theid):                          ?&gt;                     &lt;h4 style="font-style:italic;"&gt;&lt;li&gt;&lt;a href="#"&gt;&lt;?php echo $theid-&gt;post_title; ?&gt;&lt;/a&gt;&lt;/li&gt;&lt;/h4&gt;                                                  &lt;?php                     endforeach; ?&gt;          &lt;/li&gt;     &lt;?php endforeach;?&gt;     &lt;/ul&gt; &lt;/li&gt; &lt;?php endforeach; ?&gt; &lt;/ul&gt;   Currently this is working as expected but I am having problems trying to do the same thing for a specific category within my documents post type. How would I refine this code for my category 'cascade-campus-docs' within my 'documents' post type.
114158
I've found several similar question but none of them explains why the below is giving me nothing with ASC order. It works with DESC.  Basically it's a query that should list posts where the custom field values are equal or greater to the current date, then arrange it in reversed order, so the first post should be a post that's custom field are the closest the the current date.  &lt;?php query_posts($query_string . '&amp;showposts=4&amp;order=ASC&amp;post_type=custompost&amp;meta_key=mydate&amp;orderby=meta_value'); ?&gt;     &lt;?php if (have_posts()) : ?&gt;     &lt;?php while (have_posts()) : the_post(); ?&gt;          &lt;?php $todays_date = date("Y/m/j"); ?&gt;         &lt;?php $today = strtotime($todays_date); ?&gt;         &lt;?php $exp_date = get_post_meta('mydate'); ?&gt;         &lt;?php $expiration_date = strtotime($exp_date); ?&gt;         &lt;?php if ($expiration_date &gt;= $today) { ?&gt;              &lt;a href="&lt;?php the_permalink(); ?&gt;" rel="bookmark" title="&lt;?php the_title_attribute(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;      &lt;?php } else { ?&gt;     &lt;?php };?&gt;  &lt;?php endwhile; ?&gt; &lt;?php else : ?&gt; &lt;?php endif; ?&gt;    Also, I've tried many different queries but none of them worked, the above script is the latest I have.
115101
I am getting one value from webservice as a string (KM value , say 500000) . I want to display that in an inline vf page as 50,000. How to achieve this in apex controller. I am displaying the valu in a apex datatable as column value.  Please help me out  Eg ; 50000 should be 50,0000 OR 5000000 should be 5,000,000
37578
Interesting challenge. I was given a piece of code earlier, which I have modified as follows for the Posts page.  /* add time stamp */ add_filter('manage_posts_columns', 'posts_columns', 5); function posts_columns($defaults){     $defaults['your_date_col'] = __('Date');     $defaults['week_number'] = __('Wk#');     $defaults['week_in_quarter'] = __('Wk/Qtr');     return $defaults; } add_action('manage_posts_custom_column', 'posts_custom_columns', 5, 2); function posts_custom_columns($column_name, $id){     if($column_name === 'your_date_col'){     echo the_date('d M'),' ',the_time('Ha');     }     if($column_name === 'week_number'){     echo 'Here: ',the_date();     } }   Strangely, although the date format that I have given shows up in the first column ("your_date_col"), only "Here: " shows up in the second column ("week_number"). Any suggestions as to why the_date function doesn't work in the second column?
3156
Here are the args for my query :  $args = array(     'post_type' =&gt; 'news',     'meta_query' =&gt; array(         array(             'key' =&gt; 'topics',             'value' =&gt; 'sports',         )     ) );   This works when topics is a string, but not when it is an array. I'd like this query to work when topics is for example array( 'sports', 'nonprofit', etc. )  Is there a way to build meta queries with arrays as a meta_key ?
69577
I am trying to output a list of stockists in two columns from left to right, sorted alphabetically:  A | B  C | D  E | F  G | H  Currently, the code below is sorting half the posts alphabeticly and then starting half way through with the rest alphabeticly:  A | C  E | G  B | D  F | H  Any idea on where I am going wrong?  &lt;?php  query_posts(  array( 'order' =&gt; 'ASC' , 'orderby' =&gt; 'title' , 'posts_per_page' =&gt; -1 , 'post_type' =&gt; 'stockist_directory', 'regions' =&gt; 'metropolitan' ) ); if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) == 0) : $wp_query-&gt;next_post(); else : the_post(); ?&gt;  &lt;div id="left-column"&gt; &lt;h1&gt;&lt;?php the_title(); ?&gt;&lt;/h1&gt;   &lt;?php the_field('shop_address'); ?&gt;&lt;br/&gt;   &lt;?php the_field('suburb'); ?&gt;, &lt;?php the_field('postcode'); ?&gt;&lt;br/&gt;   Phone: &lt;?php the_field('phone_number'); ?&gt;&lt;br/&gt;   &lt;a href="&lt;?php the_field('website_address'); ?&gt;"&gt;Website&lt;/a&gt; &lt;/div&gt;  &lt;?php endif; endwhile; else: ?&gt; &lt;?php endif; ?&gt;  &lt;?php $i = 0; rewind_posts(); ?&gt;  &lt;?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) !== 0) : $wp_query-&gt;next_post(); else : the_post(); ?&gt;  &lt;div id="right-column"&gt;  &lt;h1&gt;&lt;?php the_title(); ?&gt;&lt;/h1&gt;   &lt;?php the_field('shop_address'); ?&gt;&lt;br/&gt;   &lt;?php the_field('suburb'); ?&gt;, &lt;?php the_field('postcode'); ?&gt;&lt;br/&gt;   Phone: &lt;?php the_field('phone_number'); ?&gt;&lt;br/&gt;   &lt;a href="&lt;?php the_field('website_address'); ?&gt;"&gt;Website&lt;/a&gt;   &lt;/div&gt; &lt;?php endif; endwhile; else: ?&gt;  &lt;?php endif; ?&gt;
112662
echo $_POST["name"]; //returns the value a user typed into the "name" field   I would like to be able to also return the text of the key. In this example, I want to return the text "name". Can I do this?
107412
When I tried to edit , I got an error saying the title must be at least 15 characters.  How did this come to happen (given that it is a new question)?   Shouldn't the title written during posting also be 15 characters? Is there some text which is removed during posting which could cause this? Like tags? Maybe it's because  are still allowed in the original post?
6769
In PHP, is there an easy way to convert a number to a word? For instance, 27 to twenty-seven.
19059
is there a way to pass a string to the &lt;apex:outputText&gt; so that it can be formatted as a currency or percent value?  Here's what I have inside a column of my visual force table:  &lt;apex:outputText value="{0, number, currecny}"&gt; &lt;apex:param value="{!row.values[1]}" /&gt; &lt;/apex:outputText   this gives me an error at runtime (when the visual force page loads), which I think may be some kind of type mismatch, where &lt;apex:outputText&gt; is expecting a Decimal or number but I am passing a string.  This is the error at runtime:     The value attribute on  is not in a valid format. It must be a positive number, and of type Number, Date, Time, or Choice.   Thanks