php - Wordpress Custom Post Loop - How to not print information from an Array that I don't need? -


been using plugin custom content type manager create custom post displays location information. hold weekly games each location - i'm trying accomplish in custom post have set of checkboxes check if venue played on monday, tuesday or wed...etc in theme i'm going have 7 day calendar. , if location checked day want title/links location printed there.

i'm giving background because dont think i'm going correct way. i'm doing in loop, , i'm pulling checkbox options in array, , if option equal monday specific day, prints locations title name etc. want setup non-technical person (kinda me lol) can add new location , pick "friday" example , code rest. got working. 2 problems though

  1. i'm running 7 loops accomplish - 1 each day. know stupid , there better solution.

  2. it's printing correct information - reading/printing each of other locations except not putting info them - know cause creating empty divs them.

note: i'm having issues posting whole code...?? deleted php tags present this

$weekly = new wp_query( array( 'post_type' => 'locations', 'posts_per_page' => 5 ) ); while ( $weekly->have_posts() ) : $weekly->the_post(); <div class="weekly-venue-spacer">  $day_array = get_custom_field('weekly_day:to_array');  if (in_array('3', $day_array)) { print_custom_field('venue_display_name'); echo "<br />"; print_custom_field('city_crossroads');   } </div> endwhile; wp_reset_postdata(); 

the '3' in in_array statement means "wednesday".

here @ image: http://i40.tinypic.com/svnee0.jpg example of empty divs being created - seen padding applied div

thanks reading. solution approach differently great.

i not sure understood correctly want , assuming did - think whole approach bit wrong/complicated .

first of all, not need 7 loops .

i have noticed have custom field - in custom field , instead of array, store 1 day need , , checking custom_field value ..

second - why use checkbook , not list ? there eventual event can in several different days ? because if every event exclusive 1 day - more easy use drop list or radio buttons.

and direct question - not know how value of custom field structured - printing of ..

edit : after reading comment , understanding better problem -

while still thinking approach bit wrong , not knowing how construct data - address immediate problem :

the code creates empty divs because tell . using while condition in code before outputting div. since query gets 5 posts - create 5 divs (some of not meet next condition , of course empty).

your function , put in human-words working :

 1. 5 post.   2. long have posts (for each post), open div.   3. if have tuesday in array - print  4. close div  5. if not finished posts (in our case, 5) - go step 2.  

it obvious code print empty div empty events..

so right move opening div tag before while condition .

that if not need check existence of events in query ..

the right way use if statement, regular wordpress loop.

the general mechanism :

   <?php if ($weekly->have_posts()) : ?> //now open div                <?php while ( $weekly->have_posts() ) : $weekly->the_post();?>       // check other conditions , print them if available.                <?php endwhile; ?> // close div      <?php endif; ?> 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -