• Resolved vladislavm

    (@vladislavm)


    Hi,

    I am using this code to get metadata from custom fields in the header of the post page:

    $mykey_values = get_post_custom_values('citation_author');
      foreach ( $mykey_values as $key => $value ) {
        echo "<meta name='citation_author' content='$value' />";
      }
    $mykey_values = get_post_custom_values('citation_publication_date');
      foreach ( $mykey_values as $key => $value ) {
        echo "<meta name='citation_publication_date' content='$value' />";
      }
    $mykey_values = get_post_custom_values('citation_doi');
      foreach ( $mykey_values as $key => $value ) {
        echo "<meta name='citation_doi' content='$value' />";
      }

    The problem is that the post page does not always have all the metadata assigned, so I get this error where it is not:

    Warning: Invalid argument supplied for foreach() in /home/r/researcorg/public_html/wp-content/themes/Aggregate-child/header.php on line 22

    Is there any way to make it checking whether the custom field with metadata is assigned to the post, and if yes then to get this data in the header, if not – skip it.

    Thank you!

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

The topic ‘metadata from custom fields in the header’ is closed to new replies.