Ask your WordPress questions! Pay money and get answers fast! (more info)

Magic Fields plugin | Call featured Latest Events on sidebar

  • SOLVED

We had a code for showing in the sidebar for What's New and Upcoming Events but it stopped working. Here is the sidebar front-end.
[[LINK href="http://cl.ly/3c1F0t001U2M0J0l0623"]]http://cl.ly/3c1F0t001U2M0J0l0623[[/LINK]]

The content is managed using Magic Fields 1.5.7 and the back-end looks like this:
[[LINK href="http://cl.ly/1h2U0c3S3p3A1v2X0E3J"]]http://cl.ly/1h2U0c3S3p3A1v2X0E3J[[/LINK]]

When you check the boxes it should work, but after a WordPress upgrade or after reaching a number of posts no content is showing up, however in Firebug it seems the loop is working:
HTML Output:
[[LINK href="http://pastebin.com/swD6pmZs"]]http://pastebin.com/swD6pmZs[[/LINK]]

screenshot:
[[LINK href="http://cl.ly/3Z1R2x313D2e2t393K2L"]]http://cl.ly/3Z1R2x313D2e2t393K2L[[/LINK]]

Here is the full code in sidebar.php.
[[LINK href="http://pastebin.com/q0JfVKf5"]]http://pastebin.com/q0JfVKf5[[/LINK]]

Let me know if you think there is an issue with the code logic or a plugin bug and if you can help.

Answers (5)

2012-01-13

Hai Bui answers:

I should post the the answer here but I think for this kind of problem (pretty hard to debug without seeing the data and doing testing), it's best you give WP admin access to one of the experts. You can PM me if you want. I'm sure we can fix it very quickly, it's better than guessing and trying everything here.


Lucian Florian comments:

Since this would require more debugging indeed, I will give Hai Bui temporary access to the site.


Lucian Florian comments:

Hai Bui helped me solve the issues and did a great job!

2012-01-13

Sébastien | French WordpressDesigner answers:

have you change anything before finding this bug ?
add a plugin ? upgrade magic field ? upgarde wordpress etc...


Lucian Florian comments:

We discovered this recently and I don't know when that happened. It happened after it reached a certain amount of posts I believe.


Sébastien | French WordpressDesigner comments:

what is the HTML outputed by your code ?


Sébastien | French WordpressDesigner comments:

OR could you give me the url of this page ?


Lucian Florian comments:

Here it is: http://pastebin.com/swD6pmZs


Sébastien | French WordpressDesigner comments:

replace your code by this code and tell me what is the output please

<?php
/**
* The Sidebar containing the primary and secondary widget areas.
*
* @package WordPress
* @subpackage Twenty_Ten
* @since Twenty Ten 1.0
*/
function filtered($name){
$name = strtolower($name);
switch($name){
case "press":
return "IPSO Press release";
default:
return $name;
}
}
global $is_homepage;
$upcoming_event = array();
$upcoming_events = array();//create the array for the homepage events
?>

<div id="primary" class="widget-area" role="complementary">
<?php
/* When we call the dynamic_sidebar() function, it'll spit out
* the widgets for that widget area. If it instead returns false,
* then the sidebar simply doesn't exist, so we'll hard-code in
* some default sidebar stuff just in case.
*/
if ( $is_homepage) : ?>
<h1 class="new">What's New</h1>
<div id="slider1">
<ul id="announcements" class="widget-container">
<?php query_posts($query_string . '&cat=*'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<? // if (get('new_item') && (get('new_removal_date')>=date("m/d/Y") || !get('new_removal_date'))) { ?>
<li id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="new-category"><?php echo filtered(get_panel_name()); ?></h1>
<h2 class="new-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php if ( get("new_custom_content")) : // Only display excerpts for archives and search. ?>
<div class="entry-summary">
<?php echo get("new_custom_content"); ?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
<?php endif; ?>
</li><!-- #post-## -->
<? // } ?>

<? //PUT THE UPCOMING EVENTS INTO AN ARRAY FOR LATER
$event = get_group('Home: Upcoming Events Area');
if(count($event)) {
$e_info = array(get_the_ID(),
the_title('','',false),
get_the_excerpt(),
get('upcoming_item'),
get('upcoming_removal_date'),
get('upcoming_custom_content'));
array_push($upcoming_events,$e_info);
} ?>
</li><!-- #post-## -->

<?php endwhile; ?>
<?php endif; ?>
</ul>
</div><!-- end slider1 -->
<?php else : ?>
<?php if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
if ($children) { ?>
<ul class="submenu">
<?php echo $children; ?>
</ul>
<?php } ?>
<?php endif;// end primary widget area ?>
</div><!-- #primary .widget-area -->
<div id="primary_footer"></div>
<?php if ( $is_homepage) : ?>
<div id="secondary" class="widget-area" role="complementary">
<ul>
<h1 class="upcoming">Upcoming Events</h1>
<?php
foreach($upcoming_events as $upcoming_event) {
if($upcoming_event[4]>=date("m/d/Y") || !$upcoming_event[4] && $upcoming_event[3]){
echo '<li><p class="title"><a href="?p='.$upcoming_event[0].'">'.$upcoming_event[1].'</a></p>';
if($upcoming_event[5]){
echo $upcoming_event[5];
}
echo '</li>';
}
}
?>
<!-- <li><p class="title">Embedded Systems Conference, Boston Sept. 20-23rd 2010</p> -->
<!-- <p> – Include a pop up box with the following info – IPSO’s Chairman Geoff Mulligan to speak Tuesday evening from 6pm -6:40 pm at the ESC theater on the benefits of IP sensors for connecting the Smart Grid</p> --><!-- </li> -->
</ul>
</div>


<div id="secondary_footer"></div>

<p class="button">
<script language="JavaScript" type="text/javascript">
// Copyright © 2005 Voormedia - WWW.VOORMEDIA.COM
var i,y,x="3c6120687265663d226d61696c746f3a696e666f406970736f2d616c6c69616e63652e6f72673f7375626a6563743d47656e6572616c253230496e666f726d6174696f6e223e4950534f20496e666f726d6174696f6e3c2f613e";y='';for(i=0;i<x.length;i+=2){y+=unescape('%'+x.substr(i,2));}document.write(y);
</script>
</p>

<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="http://www.facebook.com/pages/IPSO-Alliance/281025795247310" send="true" width="280" show_faces="false" font=""></fb:like>

<div class="socials">
<h3 class="feature-category">FOLLOW IPSO</h3>
<ul class="clearfix">
<li><a href="http://www.facebook.com/IPSOAlliance" target="_blank"><img src="<?php bloginfo( 'template_directory' ); ?>/images/socials/fb-new2.png" alt="fb-new2" width="" height="" /></a></li>
<li><a href="<?php bloginfo( 'url' ); ?>/feed" target="_blank"><img src="<?php bloginfo( 'template_directory' ); ?>/images/socials/rss-new.png" alt="rss-new" width="" height="" /></a></li>
<li><a href="http://twitter.com/IPSOAlliance" target="_blank"><img src="<?php bloginfo( 'template_directory' ); ?>/images/socials/twitter-new2.png" alt="twitter-new2" width="" height="" /></a></li>
<li><a href="http://www.linkedin.com/company/ipso-alliance" target="_blank"><img src="<?php bloginfo( 'template_directory' ); ?>/images/socials/linkedin-new.png" alt="linkedin-new" width="" height="" /></a></li>
</ul>
</div>

<?php endif;// end secondary widget area ?>


Lucian Florian comments:

It now shows all the posts for What's New area
[[LINK href="http://cl.ly/140q2L163Q3b1b3V2h1I"]]http://pastebin.com/eqNWx5q9[[/LINK]]
[[LINK href="http://cl.ly/140q2L163Q3b1b3V2h1I"]]http://cl.ly/140q2L163Q3b1b3V2h1I[[/LINK]]


Sébastien | French WordpressDesigner comments:

this is strange :
get('new_removal_date')>=date("m/d/Y")

i think you must explode and concanate dates to compare two dates.

something like that
$date = date("m/d/Y");
$date = explode("/", $date);
$date = $date[2].$date[0].$date[1];

get('new_removal_date') must have the same form $year.$mont.$day
and you can compare the dates


Sébastien | French WordpressDesigner comments:

"concatanate"
not "concanate"


Sébastien | French WordpressDesigner comments:

Now, what's the form of 'new_removal_date' ?
is it : year month day ?

2012-01-13

Luis Abarca answers:

You should use global $query_string before use it too.


function filtered($name){
<strong>global $query_string;</strong>

$name = strtolower($name);
switch($name){
case "press":
return "IPSO Press release";
default:
return $name;
}
}
global $is_homepage;
//...


Luis Abarca comments:

You should use global $query_string before use it too.


function filtered($name){
<strong>global $query_string;</strong>

$name = strtolower($name);
switch($name){
case "press":
return "IPSO Press release";
default:
return $name;
}
}
global $is_homepage;
//...


Lucian Florian comments:

I added that. Still no change


Luis Abarca comments:

I dont understand the use of * in this line, i think you can delete that &cat=*


<?php query_posts($query_string . '&cat=*'); ?>


Can you var dump the $post var in the loop and paste it the results ?


Lucian Florian comments:

I deleted that. Still does nothing. I agree code is advanced. Not sure if there is another way to write it.

2012-01-13

Christianto answers:

Hi,

this part of comparison could be failed
if(get('new_item') && (get('new_removal_date') >= date("m/d/Y") || !get('new_removal_date')))

you should use strtotime to compare it, I think date() is returning as string and could not be compare greater or less than.

$removal_date = strtotime(get('new_removal_date'));
$current_time = strtotime(date("m/d/Y"));

if(get('new_item') && ($removal_date >= $current_time || !get('new_removal_date'))){
// your loop content here
}


Hope this help..

edit: fix typos


Lucian Florian comments:

still does nothing

2012-01-13

Kannan C answers:

Did you checked the input names of the 'upcoming' fields are same as old one? because the new version of magic fields plugin has a change in the input name structure forming than the previous. I previously faced the same problem after upgrading the plugin for one of my client.


Lucian Florian comments:

As I mentioned is not the new version of Magic fields. It's the older one.