Fields Shortcodes

Fields Shortcodes

November 26, 2017
 Steve

  • Steve
    Newbie 17 points

    Hello, I have added some [FIELDS] shortcodes to my content-single-listing-directory.php page which I believe is right(please correct me if not), but they do not display on the listing page apart from the category it is in.

    Do you know why this is?
    I have attached a picture of the code on the .php page and the listing page using that code.

    Thank you very much in advance!
    -Ste

    Attachments:
    You must be logged in to view attached files.
    November 26, 2017 at 5:11 pm

  • Steve
    Newbie 17 points

    I am also using the database keys in the [FIELD] values…

    November 26, 2017 at 5:12 pm

  • Steve
    Newbie 17 points

    It is now displayed like the following, I’m not sure why some location info has now appeared:

    Attachments:
    You must be logged in to view attached files.
    November 26, 2017 at 6:26 pm
  • JamesD
    JamesD
    Titan 753 points

    Hello Steve,

    Try removing the hide”” portion at the end of all the FIELDS.

    November 26, 2017 at 9:09 pm

  • Steve
    Newbie 17 points

    Hi james thanks for the reply! I have now removed the hide”” section at the end of FIELDS but the output is still the same :(

    Attachments:
    You must be logged in to view attached files.
    November 27, 2017 at 10:45 am
  • JamesD
    JamesD
    Titan 753 points

    Ok, if pulling a specific field, then just use brackets around the custom field database key. So, for example, if ‘state’ is the database key for your “State” custom field then you would use [state]
    Note: the database key used is CaSE senSiTivE.

    To help you get started:

    <h2><b>Operator Details:</b></h2>
    [category]
    [supphone]
    [supemail]
    <br />
    <h2><b>Location:</b></h2>
    [state]
    [city]
    [businessurl]
    [businessphone]
    [address]
    [openhours]
    <br />

    Try those first to make sure it’s displaying.

    Also, You should change your ‘</br> tags to ‘<br />’ or ‘<br>’

    November 27, 2017 at 8:27 pm
    This reply was awarded the best answer by the topic poster.

  • Steve
    Newbie 17 points

    Thank you so much James that was worked perfect! & Thank you kindly for the <br> tip 😀

    November 29, 2017 at 9:55 pm
  • JamesD
    JamesD
    Titan 753 points

    You’re welcome Steve, glad to help. My apologies for not catching it quicker.

    Thanks for updating!

    November 29, 2017 at 11:20 pm
  • Trina B
    Trina B
    Newbie 68 points

    Hello @JamesD I have added my fields in the same way but links to web pages do not work well, only the url path is displayed.

    I am using a custom field database key [url] for visitors to add your website. The links do not work only the url path is displayed instead of show “Visit Link Here”, the links don’t jump.

    I have modified the file content-single-listing-business.php and I am using brackets around the customs fields database key.

    <h2><b>Basic Information:</b></h2>
    <br />
    [url]
    [phone]

    You can see the problem in the attached screenshot.

    Someone might help me, maybe I’m doing something wrong.

    Thank you

    Attachments:
    You must be logged in to view attached files.
    July 5, 2018 at 8:23 pm
  • JamesD
    JamesD
    Titan 753 points

    Hello Trina B,

    The “Visit Link Here'” is only displayed when using the [FIELDS] shortcode.

    To process a URL to be displayed as a hyperlink then the [URL] shortcode needs to be capitalized, otherwise it’ll just display as text. Also, when using [URL] the hyperlink text would display the URL as the text . No other text like ‘”Visit Link Here'” is used.

    If the above result is fine then you could just use the [URL] in the file instead of [url].

    However, IF you wanted to have ability to change the text being displayed within the hyperlink then you could create your own shortcode function to handle it.

    NOTE: By posting the code here there could potentially be things missing and/or broken, so I’ve attached a file with the working code to copy.

    This will add a new shortcode called [myurl]. You can change all references to ‘myurl’ to whatever if you like,

    The <em[myurl] shortcode functions the same as if you were to use the <em[URL] except this function allows you to pass the text to be displayed in the hyperlink.

    To add text just add the attribute (and value) linktext to the shortcode.
    So, if you wanted to have it display the “Visit Link Here” text then you would use:

    [myurl linktext="Visit Link Here"]

    Otherwise it’ll display the link with the URL as the link text.

      function myurl_shortcode($atts) {
        global $post;
        $sHyperLink = '';
        extract($atts);
        $url = get_post_meta($post->ID, 'url', true);
        if(strlen($url) > 1){
          $sHyperLink = sprintf('%s',
          					(strpos($url,"http") === false?''.$url:$url),
    						($newwindow)?' target="_blank"':'',
    						(empty($linktext)?$url:$linktext));
        }
        return $sHyperLink;
      }
      add_shortcode( 'myurl', 'myurl_shortcode' );
    

    Just add the code from the attached file to the bottom of your custom ‘_functions.php’ file.

    Attachments:
    You must be logged in to view attached files.
    July 6, 2018 at 1:15 am
  • Trina B
    Trina B
    Newbie 68 points

    @JamesD Thank you very much. It worked perfectly with both methods.

    July 6, 2018 at 3:13 am
  • Trina B
    Trina B
    Newbie 68 points

    @JamesD Is it possible to add additional [URL] shortcode? To add links to facebook, linkedin, instagram.
    It would be other fields like myurl2, myurl3, myurl4.

    Regards

    July 6, 2018 at 3:19 am
  • JamesD
    JamesD
    Titan 753 points

    @Trina B
    Yes it is. You could either add additional shortcode functions for each new shortcode you want to usef and add the code to display what you need. (like the code in the previous attachment)))

    Or alter the example code to handle additional attributes and actions.

    July 6, 2018 at 4:45 am
Viewing 13 posts - 1 through 13 (of 13 total)

Didn't find what you were after?

Chat with us now

or contact our support team