0

I'm wondering if it's possible to have Custom Fields with 2 values in WordPress posts...

Here are two examples:

enter image description here

enter image description here

For example if I want to have a field named "projects" with two values

value 1 "name"
value 2 "url"

Is it possible to do that?

BTW, I know I can do projects_name & projects_url in separate fields but that's something that doesn't suit my needs.

4
  • Are you using update_post_meta? Commented Oct 1, 2015 at 21:44
  • nope, I don't use it.. Commented Oct 1, 2015 at 21:49
  • You can store them as a comma-separated list and "explode" them later... Commented Oct 1, 2015 at 22:07
  • How are you saving your custom fields? Commented Oct 1, 2015 at 22:18

2 Answers 2

1

First off you are using post_meta as that is were custom fields is stored secondly why not just have 2 custom fields one for name and one for link you can retrieve them the same way or as previously suggested make the value delimiter separated so Text*Link them simply explode

$linkVar =  explode('*', get_post_meta($post_id, 'your key');

echo '<a href="' . $linkVar[1] . '">' . $linkVar[0] . '</a>';
Sign up to request clarification or add additional context in comments.

2 Comments

because there're going to be 7/8 of those links/names... and people that are going to use it are not really into blogs and stuff I'd like to make it as simple as possible for them...
That is simple as once you have added once everything else should be done via backend
0

Maybe my answer will be helpful for some more people who use "Custom field suite (Field Group)" WP plugin:

$loop = CFS()->get( 'your_param_slug' );
foreach ( $loop as $row => $label ) {
   echo $row; // or: echo $label
}

(See more: https://usewordpress.com/plugin-guides/custom-field-suite/custom-field-suite-displaying-loop-values/ )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.