• Mark

    (@encryptdesigns)


    So I have been working on this for over an hour and my eyes are getting tired…can anyone walk my hand through this procedure?

    https://www.coffee2code.com/archives/2004/06/30/plugin-get-custom/

    I know I have to add some code to my Themes >> Default >> index.php to the LOOP. Do I put the code anywhere between the LOOP?

    Then I have to call the PHP code on my page:

    <?php echo get_custom(‘cost’, ‘How much :’); ?>

    Right?

    Then why isn’t it working? I added 4 custom fields and am just trying to get ONE to show up named “cost”.

    I”m sure I am just missing something stupid but can’t figure it out :'(

    Oh please lend a hand!

    Grazi,

    Mark

Viewing 15 replies - 1 through 15 (of 22 total)
  • Are you sure you didn’t use:

    <?php echo c2c_get_custom('cost', 'How much :'); ?>

    According to c2c’s page linked above, the function is c2c_get_custom(), and not get_custom().

    Thread Starter Mark

    (@encryptdesigns)

    Ok that is part of the problem:) Thanks.

    But I still can’t get the information posted on the actual POST. It only shows up on the CATEGORY page and when you click the permalink it doesn’t show that info….

    This is going to rock once I get all these annoyances out of the way \:D/

    Ok, so is it possible your theme has a home.php and single.php template? These too would need to have the tag in it to get it displayed on home and single post pages, respectively.

    Thread Starter Mark

    (@encryptdesigns)

    Sweet sweet. That posts the information to the actual page.

    Now at least its posting to WP. But how do I get it to post to this page:

    https://www.foxvalleyshows.com/new/shows.php

    I don’t think I would use that same code. But I do want it pulled to a different page like everything else:)

    Would I need to put some code in the “wp-blog-header.php” file? Since I am already calling to that on all of my .php pages?

    That would depend on what “shows.php” is. Does it currently access WordPress? If it does, and entries on the page are just posts being called up in a regular Loop, you should be able to use the plugin’s function in news.php as you would in a standard theme template.

    Thread Starter Mark

    (@encryptdesigns)

    It does access WP. I have a bunch of “show listings” that pulls from my “UPCOMING SHOWS” category in WP. But for whatever reason shows.php is not pulling the data from WP. Checkout the link to see what I am referring too:

    This is where I want the info to go: (2nd one on the top in the middle saying “please”)

    https://www.foxvalleyshows.com/new/shows.php

    The info does show up here:

    https://www.foxvalleyshows.com/new/news/?p=46

    Any thoughts on what code I have to use? I would think that this information would get pulled regardless.

    Here is the code from the middle part that I am using that pulls all the “show listings” besides the “custom fields”:

    <?php ec2_get_events_list(100,'j F'); ?>
    <?php echo c2c_get_custom('cost', 'How much :'); ?>

    Thread Starter Mark

    (@encryptdesigns)

    Maybe I need to edit my Event Calendar 2 with the code to include it? That is where the <?php ec2_get_events_list(100,'j F'); ?> is being called.

    I am almost thinking that having <?php echo c2c_get_custom('cost', 'How much :'); ?> isn’t going to do anything for me on the main page…

    The problem from my perspective is I don’t know what you’re doing to call posts from your Upcoming Shows category into news.php. So let me guess: get_posts()? If so, try adding this just after the foreach($posts as $post) statement in your code:

    setup_postdata($post);

    Not all post data is available to get_posts() by default, and this will take care of it. If not using get_posts(), can you provide a little more info in this area?

    Thread Starter Mark

    (@encryptdesigns)

    Ok maybe I need to explain it better:)

    I am working on getting the Custom fields pulled to a page outside of the actual WP system here:

    https://www.foxvalleyshows.com/new/shows.php

    I have this code at the top before any HTML code:

    <?php require('./news/wp-blog-header.php'); ?>

    Then I am using the following code to pull the UPCOMING SHOWS category in WP to the shows.php page:

    <?php ec2_get_events_list(100,'j F'); ?>
    <?php echo c2c_get_custom('cost', 'How much :'); ?>

    But that isn’t doing anything so therefor I’m stuck.

    Does this help?

    Stuck is the right word. The problem here is there’s no actual post loop in shows.php; it’s all built into EventCalendar’s function. c2c_get_custom() needs to reside in some form of The Loop to act on each post, something it can’t do if run after the one ec2_get_events_list() effects (which is the case above).

    Your two options are to either nix the ec2_get_events_list() and build a custom query loop (which c2c_get_custom() can work with), or recode ec2_get_events_list() to “know” about the custom field data in each post, and output it the way you want. A third might be to convince the developer of the plugin to add such a feature.

    But in the case of that first option, if you’d point to which version of EventCalendar has the ec2_get_events_list() function, we should be able to duplicate it’s output with a specialized query loop.

    Thread Starter Mark

    (@encryptdesigns)

    Precisely what I was thinking my friend. I had mentioned that before in one of my posts.

    I’ll see what I can do with that and if you want to lend a hand with this I can post the code I am using for the EventCalendar 2 if you would like.

    Thread Starter Mark

    (@encryptdesigns)


    <?php

    load_plugin_textdomain('ec2');

    function ec2_get_calendar()
    {
    // Get options.

    // Category ID number for event posts.
    $ec2_event_category=intval( get_option('ec2_event_category') );
    // The number of month calendars to display.
    $ec2_num_months =abs(intval(get_option('ec2_num_months')));
    if(!$ec2_num_months)
    $ec2_num_months=1;
    // Highlight days with normal posts or just events.
    $ec2_show_only_events=intval(get_option('ec2_show_only_events'));
    // How to abbreviate day column headers.
    $ec2_day_length=intval(get_option('ec2_day_length'));
    if($ec2_day_length!=3)
    $ec2_day_length=1;

    // Set up the array:
    $week_begins = 0;
    $start_of_week =get_settings('start_of_week');
    if($start_of_week)
    $week_begins = intval($start_of_week);
    $weekstart =
    array(
    day => $week_begins,
    padstart => (6+$week_begins)%7,
    padend => (7+$week_begins)
    );

    global $wpdb, $m, $monthnum, $year, $timedifference, $month, $month_abbrev,
    $weekday, $weekday_initial, $weekday_abbrev, $tableposts, $tablepost2cat;

    $now = gmdate('Y-m-d H:i:59');

    if (isset($_GET['w'])) {
    $w = ''.intval($_GET['w']);
    }

    $add_hours = intval(get_settings('gmt_offset'));
    $add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours));

    // Let's figure out when we are
    // INPUT: $monthnum $year $w $m
    // OUTPUT: $thismonth $thisyear
    if (!empty($monthnum) && !empty($year)) {
    $thismonth = ''.zeroise(intval($monthnum), 2);
    $thisyear = ''.intval($year);
    } elseif (!empty($w)) {
    // week: we need to get the month from MySQL
    $thisyear = ''.intval(substr($m, 0, 4));
    $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
    $thismonth = $wpdb->get_var(
    "SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY)),'%m')"
    );
    } elseif (!empty($m)) {
    // month
    $thisyear = ''.intval(substr($m, 0, 4));
    if (strlen($m) < 6) {
    $thismonth = '01';
    } else {
    $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
    }
    } else {
    $localTime = current_time('timestamp') + get_settings('gmt_offset') * 3600;
    $thisyear = gmdate('Y',$localTime);
    $thismonth = gmdate('m',$localTime);
    }

    // Which posts are we interested in?
    if($ec2_show_only_events)
    $where_post = "category_id = $ec2_event_category";
    else
    $where_post = "( post_date_gmt <= '$now' OR category_id = $ec2_event_category )";

    //
    // Table header row
    // INPUT: $weekstart
    // OUTPUT: $header
    $day_abbr = $weekday_initial;
    if ($ec2_day_length > 1) {
    $day_abbr = $weekday_abbrev;
    }
    $header = "<thead><tr>n";
    for( $i=0; $i<7; $i++ ) {
    $wd = $weekday[ ($i+$weekstart[day]) % 7 ];
    $header .= "t<th abbr='$wd' scope='col' title='$wd'>$day_abbr[$wd]</th>n";
    }
    $header .= "</tr></thead>n";

    echo "<div id='wp-calendar'>n";

    //
    // Navigation
    // Get the next and previous month and year with at least one post
    $previous = $wpdb->get_row(
    "SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
    FROM $tableposts,$tablepost2cat
    WHERE post_date < '$thisyear-$thismonth-01'
    AND post_status = 'publish'
    AND id = post_id
    AND $where_post
    ORDER BY post_date DESC
    LIMIT 1");
    $next = $wpdb->get_row(
    "SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
    FROM $tableposts,$tablepost2cat
    WHERE post_date > '$thisyear-$thismonth-01'
    AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
    AND post_status = 'publish'
    AND id = post_id
    AND $where_post
    ORDER BY post_date ASC
    LIMIT 1");
    echo "<table class='nav'><tbody><tr>n";
    if ($previous) {
    $monthName = $month[zeroise($previous->month, 2)];
    echo "t<td id='prev'>"
    . "<a href='" . get_month_link($previous->year,$previous->month)
    . "' title='View posts for " . $monthName . ' ' .
    date('Y', mktime(0,0,0,$previous->month,1,$previous->year))
    . "'>&laquo;&nbsp;$month_abbrev[$monthName]</a></td>n";
    } else {
    echo "t<td id='prev' class='pad'>&nbsp;</td>n";
    }
    if ($next) {
    $monthName = $month[zeroise($next->month, 2)];
    echo "t<td id='next'>"
    . "<a href='" . get_month_link($next->year, $next->month)
    . "' title='View posts for " . $monthName . ' ' .
    date('Y', mktime(0,0,0,$next->month,1,$next->year))
    . "'>$month_abbrev[$monthName]&nbsp;&raquo;</a></td>n";
    } else {
    echo "t<td id='next' class='pad'>&nbsp;</td>n";
    }
    echo "</tr></tbody></table>n";

    //
    // Display months
    for( $i=0; $i<$ec2_num_months; $i++ ) {
    $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);

    //
    // Table start.
    echo "<table>n<caption>" .
    $month[zeroise($thismonth,2)] . ' ' . date('Y',$unixmonth) .
    "</caption>n";
    echo $header;

    //
    // Table body
    echo "<tbody>nt<tr>";

    if(strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') ||
    strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'camino') ||
    strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'safari')) {
    $ak_title_separator = "n";
    } else {
    $ak_title_separator = ', ';
    }

    // Get titles for day.
    // OUTPUT: array $calendar_entries
    $calendar_entries = array();
    $raw_calendar_entries = $wpdb->get_results(
    "SELECT DISTINCT
    post_title,
    DAYOFMONTH(post_date) as dom,
    (category_id = $ec2_event_category) as is_event
    FROM $tableposts,$tablepost2cat
    WHERE YEAR(post_date) = '$thisyear'
    AND MONTH(post_date) = '$thismonth'
    AND post_status = 'publish'
    AND id = post_id
    AND $where_post"
    );
    if($raw_calendar_entries) {
    foreach($raw_calendar_entries as $ent) {
    if(empty($calendar_entries[$ent->dom])) { // first one
    $calendar_entries[$ent->dom] = array( 'titles'=>'', 'class'=>'' );
    } else {
    $calendar_entries[$ent->dom]['titles'] .= $ak_title_separator;
    }
    $calendar_entries[$ent->dom]['titles'] .=
    htmlspecialchars(stripslashes($ent->post_title));
    if($ent->is_event) {
    $calendar_entries[$ent->dom]['class'] = ' class="eventday"';
    }
    }
    } // end if

    // See how much we should pad in the beginning
    // Add '-1' for Monday
    $pad = intval(date('w', $unixmonth)) + intval(-$weekstart[day]);
    while($pad < 0) $pad += 7;
    if(0 != $pad)
    echo "<td colspan='$pad' class='pad'>&nbsp;</td>";

    $daysinmonth = intval(date('t', $unixmonth));
    $now_monthday = intval(gmdate('nd',get_settings('gmt_offset')*3600+time()));
    for ($day=1; $day<=$daysinmonth; ++$day) {
    if(isset($newrow) && $newrow)
    echo "</tr>nt<tr>";
    $newrow = false;

    $monthday = 100 * $thismonth + $day;
    if($monthday == $now_monthday)
    echo '<td id="today">';
    else
    echo '<td>';

    if(array_key_exists($day,$calendar_entries)) { // any posts today?
    echo "<a href='" . get_day_link($thisyear, $thismonth, $day);
    echo "' title=\"" . $calendar_entries[$day]['titles'] . "\""
    . $calendar_entries[$day]['class'] // may be empty string
    . ">$day</a>";
    } else {
    echo $day;
    }
    echo '</td>';
    // 6 for Sunday, 0 for Monday
    if(date('w',mktime(0,0,0,$thismonth,$day,$thisyear))==$weekstart[padstart])
    $newrow = true;
    } // end loop for($day)

    // 7 to start on Sunday, 8 for Monday
    $pad=$weekstart[padend] - date('w',mktime(0,0,0,$thismonth,$day,$thisyear));
    $pad=$pad % 7;
    if($pad>0)
    echo "<td class='pad' colspan='$pad'>&nbsp;</td>";

    echo "</tr>n</tbody>n</table>";

    // Go round again
    $thisyear += intval($thismonth / 12);
    $thismonth = $thismonth % 12 + 1;
    } // end loop for $i
    echo "</div>n";
    }

    function ec2_get_events($limit, $date_format=false)
    {
    global $wpdb,$tableposts,$tablepost2cat;
    $ec2_event_category=intval( get_option('ec2_event_category') );

    if(!$date_format)
    $date_format=get_settings('date_format');

    $now = gmdate('Y-m-d H:i:59');
    $calendar_entries = $wpdb->get_results(
    "SELECT
    p.id as id,
    post_title,
    post_date
    FROM $tableposts p, $tablepost2cat p2c
    WHERE post_status = 'publish'
    AND post_date_gmt > '$now'
    AND p.id = post_id
    AND category_id = $ec2_event_category
    ORDER BY post_date
    LIMIT $limit"
    );

    echo "<p class='event_list'>n";
    if(count($calendar_entries))
    {
    $time_format=get_settings('time_format');
    foreach($calendar_entries as $entry)
    {
    echo " <p>";
    echo mysql2date($date_format,$entry->post_date);
    echo ": ";
    $permalink=get_permalink($entry->id);
    $time=__('At','ec2') . ' ' . mysql2date($time_format,$entry->post_date);
    echo "<a href='$permalink' title='$time'>$entry->post_title</a>";
    echo "</p>n";
    }
    }
    else
    {
    echo "<p>".__('No events.','ec2')."</p>n";
    }
    echo "</p>n";
    }

    function ec2_get_events_list($limit, $date_format=false)
    {
    global $wpdb,$tableposts,$tablepost2cat;
    $ec2_event_category=intval( get_option('ec2_event_category') );

    if(!$date_format)
    $date_format=get_settings('date_format');

    $now = gmdate('Y-m-d H:i:59');
    $calendar_entries = $wpdb->get_results(
    "SELECT
    p.id as id,
    post_title,
    post_date,
    post_excerpt,
    post_content
    FROM $tableposts p, $tablepost2cat p2c
    WHERE post_status = 'publish'
    AND post_date_gmt > '$now'
    AND p.id = post_id
    AND category_id = $ec2_event_category
    ORDER BY post_date
    LIMIT $limit"
    );

    echo "<p class='list_of_events'>n";
    if(count($calendar_entries))
    {
    $time_format=get_settings('time_format');
    foreach($calendar_entries as $entry)
    {
    echo " <p class='event_date'>";
    // echo mysql2date($date_format,$entry->post_date);
    // echo "</p>n";
    echo "<b><font color=FFFFFF size=2>n";
    echo "$entry->post_title";
    echo "</b></font><br>n";
    echo "<font color=FFFFFF size=1><i>n";
    echo "$entry->post_excerpt";
    echo "</font></i>n";
    echo "<p class='event_content'>n";
    echo "$entry->post_content";
    echo "</p>n";
    }
    }
    else
    {
    echo "<p>".__('No events.','ec2')."</p>n";
    }
    echo "</p>n";
    }

    /** DO NOT USE. This function is for backwards compatibility. */
    function get_event_calendar(
    $event_cat,
    $weekstart = 0, // Sunday
    $months = 1,
    $show_all = True,
    $daylength = 1 )
    {
    _e('CHANGE YOUR TEMPLATE TO USE THE ec2_get_calendar() FUNCTION!','ec2');
    }

    function ec2_action_admin_menu()
    {
    if (function_exists('add_options_page'))
    {
    add_options_page(
    'Event Calender Options',
    'EventCalendar',
    6,
    basename(__FILE__),
    'ec2_options_subpanel'
    );
    }
    }

    function ec2_options_subpanel()
    {
    if(isset($_POST['info_update']))
    {
    echo '<div class="updated"><p><strong>';
    if(isset($_POST['ec2_event_category']))
    update_option('ec2_event_category',intval($_POST['ec2_event_category']));
    if(isset($_POST['ec2_num_months']))
    update_option('ec2_num_months', intval($_POST['ec2_num_months']));
    if(isset($_POST['ec2_show_only_events']))
    update_option('ec2_show_only_events', intval($_POST['ec2_show_only_events']));
    if(isset($_POST['ec2_day_length']))
    update_option('ec2_day_length', intval($_POST['ec2_day_length']));
    _e('Options set.','ec2');
    echo '</strong></p></div>';
    }

    //
    // Get options.
    $ec2_event_category=intval( get_option('ec2_event_category') );
    $ec2_num_months =abs(intval(get_option('ec2_num_months')));
    if(!$ec2_num_months)
    $ec2_num_months=1;
    $ec2_show_only_events=intval(get_option('ec2_show_only_events'));
    $ec2_day_length=intval(get_option('ec2_day_length'));
    if($ec2_day_length!=3)
    $ec2_day_length=1;

    ?>

    <div class=wrap>
    <form method="post">
    <h2>Event Calender Options</h2>
    <table width="100%" cellspacing="2" cellpadding="5" class="editform">
    <tr valign="middle">
    <th width="33%" scope="row"><? _e('Event category','ec2') ?>:</th>
    <td>
    <select name="ec2_event_category">
    <?php wp_dropdown_cats( 0, $ec2_event_category ); ?>
    </select>
    </td>
    </tr>
    <tr valign="middle">
    <th width="33%" scope="row"><? _e('Number of months','ec2') ?>:</th>
    <td>
    <input type="text" name="ec2_num_months" value="<?php echo $ec2_num_months; ?>" />
    </td>
    </tr>
    <tr valign="middle">
    <th width="33%" scope="row"><? _e('Show all categories in calendar','ec2') ?>:</th>
    <td>
    <select name="ec2_show_only_events">
    <option value='1'<?php if($ec2_show_only_events) echo "selected='selected'" ?> >
    <?php _e('Only Show Events','ec2'); ?>
    </option>
    <option value='0'<?php if(!$ec2_show_only_events) echo "selected='selected'" ?> >
    <?php _e('Show All Posts','ec2'); ?>
    </option>
    </select>
    </td>
    </tr>
    <tr valign="middle">
    <th width="33%" scope="row"><? _e('Show day names as','ec2') ?>:</th>
    <td>
    <select name="ec2_day_length">
    <option value='1'<?php if(3!=$ec2_day_length) echo "selected='selected'" ?> >
    <?php _e('Single Letter','ec2'); ?>
    </option>
    <option value='3'<?php if(3==$ec2_day_length) echo "selected='selected'" ?> >
    <?php _e('3-Letter Abbreviation','ec2'); ?>
    </option>
    </select>
    </td>
    </tr>
    </table>

    <div class="submit"><input type="submit" name="info_update" value="<?php
    _e('Update options','ec2')
    ?> &raquo;" /></div>
    </form>

    <h3>EXAMPLE SIDEBAR CODE:</h3>

    <pre><code> <li id="calendar">
    <?php ec2_get_calendar(); ?>
    </li>
    <li><?php _e('Events:'); ?>
    <?php ec2_get_events(5,'j F'); ?>
    </li></code></pre>

    </div> <?
    }

    /** Eliminate date restrictions if the query is day- or category- specific. */
    function ec2_filter_where($where)
    {
    global $wp_query,$tablepost2cat,$wpdb;
    $result=$where;

    if($wp_query->is_single ||
    $wp_query->is_page ||
    $wp_query->is_date ||
    $wp_query->is_year ||
    $wp_query->is_month ||
    $wp_query->is_day ||
    $wp_query->is_time ||
    $wp_query->is_category)
    {
    $ec2_event_category=intval( get_option('ec2_event_category') );
    // Only apply the date restriction to non-event categories.
    $post_list=$wpdb->get_results(
    "SELECT DISTINCT(post_id) FROM $tablepost2cat " .
    "WHERE category_id=$ec2_event_category" );
    if(count($post_list))
    {
    $post_list_str='-1'; // start with a dummy value
    foreach($post_list as $p)
    $post_list_str.=",$p->post_id";
    $result=
    preg_replace(
    "/AND +(post_date_gmt *<= *'[-: 0-9]+') +/",
    'AND ($1 OR id IN ('.$post_list_str.') ) ',
    $where
    );
    }
    }
    return $result;
    }

    //
    // Hook in...

    add_action('admin_menu', 'ec2_action_admin_menu');
    add_filter('posts_where','ec2_filter_where');

    ?>

    Thread Starter Mark

    (@encryptdesigns)

    There is the plugin as it is altered from its original version. If you see anything let me know and I’ll look into more later today:o)

    Thanks again for your help so far and I am sure this will be helpful for other people who are working with that Plugin.

    Uh, in future note that it’s not a good idea to post full scripts into the forums. For a lot of reasons. We usually recommend sites like:

    https://paste.uni.cc
    https://pastebin.com

    But I’ll look at the…code and see what I come up with.

    Thread Starter Mark

    (@encryptdesigns)

    My Bad. Sorry everyone:o)

    Thanks for the looksie though:)

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘Can’t get “Get Custom ” to work for the life of me >:(’ is closed to new replies.