Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End [Solved] Custom Fields get_post_meta question

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #26234
    minuscircus
    Member

    I am creating a post template in my wordpress.

    I need to have:
    1/ a dynamic src inside an image – so I can place "artist-image" as custom field and the path. This works.
    2/ I need to a link underneath that contains a website link
    3/ pretty much the same as number 2

    Here’s my PHP – 2 and 3 aren’t working – but number 1 is. What am I doing wrong? Any ideas?

    <!– I NEED TO POST AN IMAGE FROM THE IMG and THEN TWO SEPERATE LINKS BELOW – 1/ WEBSITE 2/ MYSPACE URL –>

    <div class="artist-details">
    <?php
    $artistimageCode = get_post_meta ($post ->ID, ‘artist-image’, true);
    $websiteCode = get_post_meta ($post ->ID, ‘website-address’, true);
    $myspaceCode = get_post_meta ($post ->ID, ‘myspace’, true);
    ?>

    <img src="<?php echo $artistimageCode; ?>" width="200" height="250" alt="music box for life artist" />
    <p>Website: <a href="<?php echo $websiteCode; ?>" target="_blank"></a></p>
    <p>Myspace: <a href="<?php echo $myspaceCode; ?>" target="_blank"></a></p>
    </div>
    <!– artist details close –>

    <!– ARTIST CLOSE –>

    #64655
    TheDoc
    Member

    *Moved to CMS section since it’s dealing with Custom Fields*

    I don’t think I can answer this without a little more information. What is it outputting that "isn’t working"? If you have a link to the page that’s doing it, that’d help too.

    Also, you might want to consider changing the code slightly. What if the artist doesn’t have a Myspace page? I would do something like this:

    Code:
    if ($artistimageCode) {
    echo ‘music box for life artist‘;
    }
    if ($websiteCode) {
    echo ‘

    Website:

    ‘;
    }
    if ($myspaceCode) {
    echo ‘

    Myspace:

    ‘;
    }

    This way, if they don’t have a website, it won’t show "Website: ", it’ll just bump the Myspace up one line.

    #64671
    minuscircus
    Member

    Hey DOC

    I didnt know where the post went – so I reposted after searching for it!

    Thank for the suggestion – this is more of testing the water ie custom fields. Every artist involved the project with have a website and a myspace page. The problem is when I try to ADD a custom field in the backend of WP it says "An unidentified error has occured".

    So let’s say this is what I wanted:

    Code:

    ID, ‘artist-image’, true);
    $websiteCode = get_post_meta ($post ->ID, ‘website-address’, true);
    $myspaceCode = get_post_meta ($post ->ID, ‘myspace’, true);
    ?>

    #64672
    TheDoc
    Member

    I’ve never heard of WP doing that, might be a problem with your install. You should technically be allowed to have unlimited custom fields. If you try deleting your first custom field and adding another, what happens?

    #64696
    minuscircus
    Member

    hey DOC

    This really stumped me too – as my scripting looked to be pretty much ok. But I’ve fixed it – it must have been some weird little bug in my system.

    I updated my version of WP to the latest (just in case 2.83 > 2.84) and deleted all my previous entries for custom fields. I re-inputted them and it’s working! I have no idea what the exact cause was – but it was worth the try :-)

    Thanks for that!

    Have a great weekend!

    #64719
    minuscircus
    Member

    Actually Doc,

    I’ve coem back with my tail between my legs! I’m trying to do what you suggested ie with the "if" statement as some of the artists only have myspace accounts (and not band websites) – this is what i have and what is working for me at the moment (without the IF statement)

    Code:
    ID, ‘artist-image’, true);
    $websiteCode = get_post_meta ($post ->ID, ‘website-address’, true);
    $myspaceCode = get_post_meta ($post ->ID, ‘myspace’, true);
    ?>

    more info

    ” target=”_blank”>Visit Website
    ” target=”_blank”>Visit Myspace

    My attempt at implementing your code:

    Code:
    ID, ‘artist-image’, true);
    $websiteCode = get_post_meta ($post ->ID, ‘website-address’, true);
    $myspaceCode = get_post_meta ($post ->ID, ‘myspace’, true);
    ?>

    more info

    Website:

    ‘;
    }
    if ($myspaceCode) {
    echo ‘

    Myspace:

    ‘;
    }
    ?>

    Any ideas? Thanks :-/

    #64728
    Dominic
    Member

    I’m not all that good at php, but what you have done with Doc’s code looks ok to me!

    I’m assuming the problem is that the links aren’t showing up at all?

    I’m guessing you have some css styling on the anchor tags to give them height and width?
    ie., you have this:

    Code:
    echo ‘

    Website:

    ‘;

    rather than:

    Code:
    echo ‘

    Website: Visit Website

    ‘;

    Other than that, I sometimes find that my supposedly empty custom fields (when made using the flutter plugin) have blank characters in them.
    So I use the following:

    Code:
    Website:

    ‘;
    }
    ?>

    I hope I haven’t led you up the garden path here. I’m pretty new to php.

    #64729
    Dominic
    Member

    Actually… ignore all that php stuff at the bottom. I’m almost certain the issue I hinted at is exclusively related to custom fields created with the flutter plugin.
    Sorry :roll:

Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘Back End’ is closed to new topics and replies.