473,513 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Coding Help :: PHP & Wordpress using categories and custom fields referencing dates

site: http://www.pleinairbc.com/event-listings/

I have some code to help filter posted events based on location name, which is defined with a sub category under the main category 'location' (id 35). The location name in the drop box will only display if the end date is the same or less than todays date. The end date is defined in the 'custom field' area when posting via worpress 3.x as the variable 'endDate' looking like 2010/10/08 (October 8, 2010)

All location names (Langley, Coquitlam, etc)are parented to the category 'location'.

The issue is that two 'locations' (Langley and Salt Spring Island) for events are showing up in the list which have come and gone. And one (Rocky Mountains) is not showing up at all.

My code is below. Please help me out.

Cheers,

Michael


Expand|Select|Wrap|Line Numbers
  1. <a name="results"></a>
  2.  
  3. <div style="float: none;">
  4.  
  5. <div  style="float: left;">
  6.  
  7. <select name="event-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> 
  8.  
  9. <option value=""><?php echo attribute_escape(__('Select Type')); ?></option> 
  10.  
  11. <option value="/?page_id=284">All Events</option>
  12.  
  13. <option value="/?page_id=284&eventtype=12">Free</option>
  14.  
  15. <option value="/?page_id=284&eventtype=52">$ Low Cost <$150</option>
  16.  
  17. <option value="/?page_id=284&eventtype=13">$$ Paid Workshops >$150</option>
  18.  
  19. </select><br /><br />
  20.  
  21. </div><div style="float: left;">
  22.  
  23. <div  style="float: left;">&nbsp;&nbsp;&nbsp;</div>
  24.  
  25. <?php
  26.  
  27.     query_posts('cat=12,13,52&meta_key=endDate&meta_compare=>=meta_value= '.$todaysDate.' &orderby=meta_value&order=ASC');
  28.  
  29.     $the_post_cats = array();
  30.  
  31.         if (have_posts()) : while (have_posts()) : the_post();
  32.  
  33.     $the_post_cats = array_merge($the_post_cats, wp_get_post_categories($post->ID)); 
  34.  
  35. ?>
  36.  
  37.         <?php endwhile; endif; ?>
  38.  
  39. <select style="float: left;" name="event-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> 
  40.  
  41.  <option value=""><?php echo attribute_escape(__('Select Location')); ?></option> 
  42.  
  43.  <option value="/?page_id=284">All Locations</option>
  44.  
  45. <?php wp_list_categories( $args ); ?> 
  46.  
  47.  
  48.  <?php 
  49.  
  50.   $categories= get_categories('child_of=35');
  51.  
  52.   foreach ($categories as $cat) {
  53.  
  54.  
  55.     $option = '<option value="/?page_id=284&location='.$cat->term_id.'">';
  56.  
  57.     $option .= $cat->cat_name;
  58.  
  59.     $option .= '</option>';
  60.  
  61.     if(!in_array($cat->term_id , $the_post_cats)) echo $option;
  62.  
  63.   }
  64.  
  65. ?>
  66.  
  67. </select>
  68.  
  69. </div></div>
  70.  
  71. <br clear="all" /><br />
  72.  
  73. <?php $todaysDate = date('Y/m/d'); //echo $todaysDate;
  74.  
  75. if(isset($_GET["eventtype"])) {$eventtype= $_GET["eventtype"];} else {$eventtype = "12,13,52";}
  76.  
  77. if(isset($_GET["location"])) {$eventtype= $_GET["location"]; echo 'Showing results for the following location:<br /><span style="color: orange; font-weight: bold;">' . get_cat_name( $eventtype) . '</span><br /><br />';}
  78.  
  79.     query_posts('showposts=20&cat=' . $eventtype . '&meta_key=endDate&meta_compare=>=&meta_value=' . $todaysDate . '&orderby=meta_value&order=ASC');
  80.  
  81. $the_dimension = 0 ; $posts2print = array();
  82.  
  83.         if (have_posts()) : while (have_posts()) : the_post();
  84.  
  85.     $sdate = get_post_custom_values('startDate', $post->ID);
  86.  
  87.     $edate = get_post_custom_values('endDate', $post->ID);
  88.     if($sdate == '') $sdate = $edate;
  89.  
  90.         $the_post_title = $post->post_title;
  91.  
  92.     $the_post_permalink = get_permalink();
  93.  
  94.     $typeofevent = '';
  95.  
  96.     if (in_category('12')) $typeofevent = ' <span style="font-size: small; color: #2C9B2E;">Free Event!</span>';
  97.  
  98.         if (in_category('52')) $typeofevent = ' <span style="font-size: small; color: #1194C3;">Low Cost Event</span>';
  99.  
  100.     if (in_category('13')) $typeofevent = ' <span style="font-size: small; color: #C39111;">Paid Workshop</span>';
  101.  
  102.     $locationregion = get_post_custom_values('region', $post->ID);
  103.  
  104. $cur_post = array($the_dimension => array("sdate" => $sdate[0], "edate" => $edate[0], "ptitle" => $the_post_title, "ppermalink" => $the_post_permalink , "tevent" => $typeofevent , "lregion" => $locationregion[0]));
  105.  
  106.  
  107. $posts2print = $posts2print + $cur_post; $the_dimension++;?>
  108.  
  109. <?php endwhile; endif; ?>
  110.  
Oct 18 '10 #1
3 1788
JKing
1,206 Recognized Expert Top Contributor
Hi, when you say list are you referring to the drop down for locations or the list of events below? I just visited your site and I only see two events listed both for west vancouver.
Nov 8 '10 #2
mrking
28 New Member
I am referring to the list in the drop down for 'locations'.

Yes, there are two events listed for West Vancouver. That location should be the only one showing up in the 'locations' drop down menu.
Nov 8 '10 #3
JKing
1,206 Recognized Expert Top Contributor
On line 61 there is an if statement inside a for each loop. This is where you determine what options should be printed.

Try printing out $the_post_cats and verifying which category ids are in it and compare them to the category ids being printed to the drop down.

If the results aren't what you expect you may need to rework your if statement logic.
Nov 9 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1403
by: Adrian | last post by:
I'm writing the scope of an app that will be built in VB.Net, using Access at first. One of the requirements is to have user-defined fields for particular tables. What is the best way to provide...
4
2479
by: Stewart Allen | last post by:
I'm trying to filter a table that has 2 date fields, the first date will always have a value but the second will only occasionally has a value. Each date field also has a corresponding text field...
2
442
by: Ron | last post by:
I need to write a custom textbox control that references an object located in the Global.asax class, but I can't compile the control into a DLL without including the reference to the project DLL...
1
1624
by: thechaosengine | last post by:
Hi all, Can somebody tell me if the built in paging support for the datagrid works when using a custom collection and a custom business object as the data. I was well pleased when I found that...
1
1616
by: Luciano A. Ferrer | last post by:
Wich script package do you recommend me? The goal is to build a site for news/articles, using categories, with comments by users... and maybe a forum I was thinking on xoops, but what about...
2
2510
by: prabhupr | last post by:
Hi Folks I was reading this article (http://www.dotnetbips.com/articles/displayarticle.aspx?id=32) on "Custom Attribute", written by Bipin. The only thing I did not understand in this article...
8
12815
by: Remington | last post by:
I am using windows 2000pro with access 2000. I am trying to make a database for our HR department, that would allow our HR Director to type in an employee's ID number into a form and then select...
2
8329
nirmalsingh
by: nirmalsingh | last post by:
hai everybody, just like we write html coding in c# using response.write("<label></label>"); could i write javascript? help me with sample coding plz.....
1
4941
by: mr k | last post by:
Hi, I wanted to use mail merge with forms but Text form fields are not retained during mail merge in Word, I got the code from Microsoft but it doesn't remember the text form field options such as...
0
1591
by: wimdows | last post by:
Hi, I've successfully added custom fields to the Task Work Item template, using the Process Editor (and opening from server). However, I would like to also see these items in the field list...
0
7175
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7391
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7553
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7120
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5697
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4754
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
466
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.