Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter bm-rinths

    (@bm-rinths)

    Hi,

    I have Version 5.5.3, what I’m trying to do is create categories in events which are then associated with images, so when a user selects that category the image associated to it will display on the front end.

    But I also want these categories to appear as pre selected when the same user then goes into create their event – so to tie the event & listing together, I can send you a link to the dev site if you need

    Thread Starter bm-rinths

    (@bm-rinths)

    HI,

    I’m getting an error message:

    Fatal error: Cannot use object of type stdClass as array in /var/www/vhosts/default-domain.com/httpdocs/wp-content/themes/atlas-child/content-single-listing.php on line 341

    I have changed the custom fields to allow the user to select different types of sports events.
    I need to display the logos for media category selected based on the users selection (which can be more then one), but getting the above stdClass error instead.

    My array is now:

    array(4) {
    [0]=> array(23)
    {
    [“select_live_sports_event”]=> string(8) “football”
    [“date_&_time_”]=> string(15) “5/18/14 2:00 pm” [“select_football_teams_playing”]=> object(stdClass)#3522 (10)
    {
    [“term_id”]=> int(667)
    [“name”]=> string(7) “Everton”
    [“slug”]=> string(7) “everton”
    [“term_group”]=> int(0)
    [“term_taxonomy_id”]=> int(743)
    [“taxonomy”]=> string(14) “media_category”
    [“description”]=> string(0) “”
    [“parent”]=> int(639) [“count”]=> int(1)
    [“filter”]=> string(3) “raw” }
    [“select_football_team_playing_2”]=> object(stdClass)#3518 (10)
    {
    [“term_id”]=> int(670)
    [“name”]=> string(9) “Liverpool”
    [“slug”]=> string(9) “liverpool”
    [“term_group”]=> int(0)
    [“term_taxonomy_id”]=> int(746)
    [“taxonomy”]=> string(14) “media_category”
    [“description”]=> string(0) “”
    [“parent”]=> int(639)
    [“count”]=> int(1)
    [“filter”]=> string(3) “raw”
    }
    [“basketball_team1”]=> string(0) “”
    [“basketball_team2”]=> string(0) “” [“american_college_conference_team_1”]=> string(0) “” [“american_college_conference_team_2”]=> string(0) “” [“ice_hockey_team_1”]=> string(0) “”
    [“ice_hockey_team_2”]=> string(0) “”
    [“baseball_team_1”]=> string(0) “”
    [“baseball_team_2”]=> string(0) “”
    [“formula_1_team”]=> string(0) “”
    [“formula_1_team_2”]=> string(0) “”
    [“gaa_team_1”]=> string(0) “”
    [“gaa_team_2”]=> string(0) “”
    [“golf_tournament_team_1”]=> string(0) “”
    [“golf_tournament_team_2”]=> string(0) “”
    [“rugby_league_team_1”]=> string(0) “”
    [“rugby_team_2”]=> string(0) “”
    [“world_cup_game_team_1”]=> string(0) “”
    [“world_cup_game_team_2”]=> string(0) “”
    [“olympics_game”]=> string(0) “”
    }
    [1]=> array(23)
    {
    [“select_live_sports_event”]=> string(11) “formula one” [“date_&_time_”]=> string(15) “5/30/14 1:00 pm” [“select_football_teams_playing”]=> string(0) “” [“select_football_team_playing_2”]=> string(0) “” [“basketball_team1”]=> string(0) “”
    [“basketball_team2”]=> string(0) “” [“american_college_conference_team_1”]=> string(0) “” [“american_college_conference_team_2”]=> string(0) “” [“ice_hockey_team_1”]=> string(0) “”
    [“ice_hockey_team_2”]=> string(0) “”
    [“baseball_team_1”]=> string(0) “”
    [“baseball_team_2”]=> string(0) “”
    [“formula_1_team”]=> object(stdClass)#3521 (10)
    {
    [“term_id”]=> int(984)
    [“name”]=> string(23) “Australia F1 Grand Prix”
    [“slug”]=> string(23) “australia-f1-grand-prix”
    [“term_group”]=> int(0)
    [“term_taxonomy_id”]=> int(1066)
    [“taxonomy”]=> string(16) “formula_one_logo”
    [“description”]=> string(0) “”
    [“parent”]=> int(0)
    [“count”]=> int(1)
    [“filter”]=> string(3) “raw” }
    [“formula_1_team_2”]=> object(stdClass)#3519 (10)
    {
    [“term_id”]=> int(986)
    [“name”]=> string(10) “Bahrain F1”
    [“slug”]=> string(10) “bahrain-f1”
    [“term_group”]=> int(0)
    [“term_taxonomy_id”]=> int(1068)
    [“taxonomy”]=> string(16) “formula_one_logo”
    [“description”]=> string(0) “”
    [“parent”]=> int(0) [“count”]=> int(1)
    [“filter”]=> string(3) “raw”
    }
    [“gaa_team_1”]=> string(0) “”
    [“gaa_team_2”]=> string(0) “”
    [“golf_tournament_team_1”]=> string(0) “”
    [“golf_tournament_team_2”]=> string(0) “”
    [“rugby_league_team_1”]=> string(0) “”
    [“rugby_team_2”]=> string(0) “”
    [“world_cup_game_team_1”]=> string(0) “”
    [“world_cup_game_team_2”]=> string(0) “”
    [“olympics_game”]=> string(0) “” } [2]=> array(23)
    {
    [“select_live_sports_event”]=> string(8) “olympics”
    [“date_&_time_”]=> string(16) “5/27/16 10:00 am” [“select_football_teams_playing”]=> string(0) “” [“select_football_team_playing_2”]=> string(0) “” [“basketball_team1”]=> string(0) “”
    [“basketball_team2”]=> string(0) “” [“american_college_conference_team_1”]=> string(0) “” [“american_college_conference_team_2”]=> string(0) “” [“ice_hockey_team_1”]=> string(0) “”
    [“ice_hockey_team_2”]=> string(0) “”
    [“baseball_team_1”]=> string(0) “”
    [“baseball_team_2”]=> string(0) “”
    [“formula_1_team”]=> string(0) “”
    [“formula_1_team_2”]=> string(0) “”
    [“gaa_team_1”]=> string(0) “”
    [“gaa_team_2”]=> string(0) “”
    [“golf_tournament_team_1”]=> string(0) “”
    [“golf_tournament_team_2”]=> string(0) “”
    [“rugby_league_team_1”]=> string(0) “”
    [“rugby_team_2”]=> string(0) “”
    [“world_cup_game_team_1”]=> string(0) “”
    [“world_cup_game_team_2”]=> string(0) “”
    [“olympics_game”]=> string(3) “931” } [3]=> array(23)
    {
    [“select_live_sports_event”]=> string(19) “american conference” [“date_&_time_”]=> string(17) “10/23/14 12:00 am” [“select_football_teams_playing”]=> string(0) “” [“select_football_team_playing_2”]=> string(0) “” [“basketball_team1”]=> string(0) “”
    [“basketball_team2”]=> string(0) “” [“american_college_conference_team_1”]=> object(stdClass)#3515 (10)
    {
    [“term_id”]=> int(935)
    [“name”]=> string(25) “Atlantic Coast Conference”
    [“slug”]=> string(25) “atlantic-coast-conference”
    [“term_group”]=> int(0)
    [“term_taxonomy_id”]=> int(1015)
    [“taxonomy”]=> string(16) “american_college”
    [“description”]=> string(0) “”
    [“parent”]=> int(0)
    [“count”]=> int(1)
    [“filter”]=> string(3) “raw”
    }
    [“american_college_conference_team_2”]=> object(stdClass)#3513 (10) { [“term_id”]=> int(937)
    [“name”]=> string(18) “Big Sky Conference”
    [“slug”]=> string(18) “big-sky-conference”
    [“term_group”]=> int(0)
    [“term_taxonomy_id”]=> int(1017)
    [“taxonomy”]=> string(16) “american_college”
    [“description”]=> string(0) “”
    [“parent”]=> int(0)
    [“count”]=> int(1)
    [“filter”]=> string(3) “raw” }
    [“ice_hockey_team_1”]=> string(0) “”
    [“ice_hockey_team_2”]=> string(0) “”
    [“baseball_team_1”]=> string(0) “”
    [“baseball_team_2”]=> string(0) “”
    [“formula_1_team”]=> string(0) “”
    [“formula_1_team_2”]=> string(0) “”
    [“gaa_team_1”]=> string(0) “”
    [“gaa_team_2”]=> string(0) “”
    [“golf_tournament_team_1”]=> string(0) “”
    [“golf_tournament_team_2”]=> string(0) “”
    [“rugby_league_team_1”]=> string(0) “”
    [“rugby_team_2”]=> string(0) “”
    [“world_cup_game_team_1”]=> string(0) “”
    [“world_cup_game_team_2”]=> string(0) “”
    [“olympics_game”]=> string(0) “”
    }
    }

    Here is what I have set up:

    <?php
    $rows = get_field(‘live_bar_sports_event’);
    $first_row = $rows[0];
    $term_id_1 = $first_row[‘select_football_teams_playing’][0]->term_id;
    $args = array(
    ‘post_type’ => ‘attachment’,
    ‘post_status’ => ‘inherit’,
    ‘posts_per_page’ => 1,
    ‘tax_query’ => array(
    array(
    ‘taxonomy’ => ‘media_category’,
    ‘field’ => ‘id’,
    ‘terms’ => array($term_id_1)
    )
    )
    );

    $the_query = new WP_Query( $args );

    while ( $the_query->have_posts() )
    {
    $the_query->the_post();
    echo wp_get_attachment_image( get_the_ID(), ‘thumbnail’);
    }
    wp_reset_query();

    ?> vs
    <?php

    $rows = get_field(‘live_bar_sports_event’);
    $first_row = $rows[0];
    $term_id_2 = $first_row[‘select_football_team_playing_2’][0]->term_id;
    $args = array(
    ‘post_type’ => ‘attachment’,
    ‘post_status’ => ‘inherit’,
    ‘posts_per_page’ => 1,
    ‘tax_query’ => array(
    array(
    ‘taxonomy’ => ‘media_category’,
    ‘field’ => ‘id’,
    ‘terms’ => array($term_id_2)
    )
    )
    );

    $the_query = new WP_Query( $args );

    while ( $the_query->have_posts() )
    {
    $the_query->the_post();
    echo wp_get_attachment_image( get_the_ID(), ‘thumbnail’);
    }
    wp_reset_query(); ?>

    This is repeated for each media Category :
    <?php

    $rows = get_field(‘live_bar_sports_event’);
    $first_row = $rows[0];
    $term_id_1 = $first_row[‘basketball_team1’][0]->term_id;
    $args = array(
    ‘post_type’ => ‘attachment’,
    ‘post_status’ => ‘inherit’,
    ‘posts_per_page’ => 1,
    ‘tax_query’ => array(
    array(
    ‘taxonomy’ => ‘baseball_logo’,
    ‘field’ => ‘id’,
    ‘terms’ => array($term_id_1)
    )
    )
    );

    $the_query = new WP_Query( $args );

    while ( $the_query->have_posts() )
    {
    $the_query->the_post();
    echo wp_get_attachment_image( get_the_ID(), ‘thumbnail’);
    }
    wp_reset_query();

    ?> vs

    <?php

    $rows = get_field(‘live_bar_sports_event’);
    $first_row = $rows[0];
    $term_id_2 = $first_row[‘basketball_team2’][0]->term_id;
    $args = array(
    ‘post_type’ => ‘attachment’,
    ‘post_status’ => ‘inherit’,
    ‘posts_per_page’ => 1,
    ‘tax_query’ => array(
    array(
    ‘taxonomy’ => ‘baseball_logo’,
    ‘field’ => ‘id’,
    ‘terms’ => array($term_id_2)
    )
    )
    );

    $the_query = new WP_Query( $args );

    while ( $the_query->have_posts() )
    {
    $the_query->the_post();
    echo wp_get_attachment_image( get_the_ID(), ‘thumbnail’);
    }
    wp_reset_query();?>

    Thread Starter bm-rinths

    (@bm-rinths)

    Hi,

    You’ve been a great help! But I still can’t get it to work, I’ve checked my custom field names and sub field names over several times and did a print_r statement, which shows the following;

    Array ( [0] => Array (
    [choose_live_sports_events] => Array ( [0] => football )
    [sports_events_date_time] => 4/27/14 3:34 pm
    [live_sports_event_logo_1] => Array ( [0] => stdClass Object ( [term_id] => 656
    [name] => Arsenal [slug] => arsenal [term_group] => 0 [term_taxonomy_id] => 732
    [taxonomy] => media_category [description] => [parent] => 639 [count] => 1
    [filter] => raw
    )
    )
    [live_sports_event_logo_2] => Array ( [0] => stdClass Object ( [term_id] => 673
    [name] => Manchester United [slug] => manchester-united [term_group] => 0
    [term_taxonomy_id] => 749 [taxonomy] => media_category [description] =>
    [parent] => 639 [count] => 1 [filter] => raw
    )
    )
    )
    )

    Could it be because I have a conditional statement in my custom field ? Do I have to add an extra parameter somewhere? also I notice its not the first row that I need to display the image for its actually the rows starting for : live_sports_event_logo_1 & live_sports_event_logo_2

    Here is what I have so far:

    $rows = get_field(‘live_sports_event’);
    $first_row = $rows[0];
    $term_id = $first_row[‘live_sports_event_logo_1’];

    Thread Starter bm-rinths

    (@bm-rinths)

    Thanks, your quite right by adding the term id explicitly it displays the image.

    But the variable for my $term_id which is the name of the taxonomy field in advance custom fields returns a boolean (false), can you shed any light on this at all? Or advise what I’m doing wrong? Thanks again

    Thread Starter bm-rinths

    (@bm-rinths)

    unfortunately tax_query doesn’t display any results, which is why I was using meta_query.

    It worked when the advance custom field was not a repeater field, but for some reason when I use the same code in a acf repeater field nothing comes up.

    Thread Starter bm-rinths

    (@bm-rinths)

    Hi,
    Thanks for the speedy response, I’ve been stuck on this bit for days!
    I think so…. here is the full code;

    <?php
    $term_id = get_field(‘live_sports_event’);
    $term_id = get_sub_field(‘live_sports_event_logo_1’);

    $args = array(
    ‘post_type’ => ‘attachment’,
    ‘post_status’ => ‘inherit’,
    ‘posts_per_page’ => 1,
    ‘meta_query’ => array(
    array(
    ‘taxonomy’ => ‘media_category’,
    ‘field’ => ‘id’,
    ‘term’ => $term_id
    )
    )
    );
    $the_query = new WP_Query( $args );

    while ( $the_query->have_posts() )
    {
    $the_query->the_post();
    echo wp_get_attachment_image( get_the_ID(), ‘thumbnail’);
    }
    wp_reset_query();
    ?>

Viewing 6 replies - 1 through 6 (of 6 total)