Support has been upgraded!
The Support Forum is closed. Not to worry! Providing the top quality support you expect and we're known for will continue! We're not ending support, just changing where you submit requests. This will provide you with the best experience possible.
Premium Support
Have you purchased an addon for Connections such as one of our premium templates or extensions with a valid license and you need help?
Please open a Support Ticket in your user account.
Free Support
Are you using the free Connections plugin? Don't worry, you are still very important to us! We are still providing you with the same high quality support that we're known for.
Please open a new support topic in the WordPress support forums for Connections.
Tagged: 8.5.18, category, custom field
- This topic has 7 replies, 2 voices, and was last updated 10 years, 1 month ago by
Steven Zahm.
-
AuthorPosts
-
07/03/2016 at 1:40 pm #381394
Bene
GuestHey,
I have the following problem. I’ve added a custom field due to your Guide: Add Custom Text Field. This works perfectly.
But now I have a small problem:
Some people have two functions in our club: e.g. official AND coach.So there are two sites with [connections category='4'] and [connections category='5'], in first one I want to show my custom field: team, but not in second.
Site 1:
Mr X
Title: PresidentSite 2:
Mr X
Team (custom field): first teamIs this possible to do whit shortcodes or in PHP?
Something like
if ( ! empty( $text ) && $getCategoryId()==4 ) echo ‘‘ . esc_html( $text ) . ‘
‘;
Or would it be better to create a contact twice (so I can use the title field for each category)
Thanks for a hint!
Regards Bene
07/04/2016 at 9:55 am #381442Steven Zahm
Keymaster@ Bene
re: Is this possible to do whit shortcodes or in PHP?
Yes, this is what I would recommend…
Put this it the top of the
card.php/card-single.phpfiles.foreach ( $entry->getCategory() as $category ) { $categories[] = $category->slug; }The to display the field use:
if ( ! empty( $text ) && in_array( 'meta_key', $categories ) ) { echo '<p>' . esc_html( $text ) . '</p>'; }You would change
meta_keyto the name you entered in the custom field. It will need to be exactly the same to work.Hope that helps, let me know.
07/04/2016 at 12:55 pm #381461Bene
GuestHey,
thanks for the hint.
It worked, but I think you mixed something up :-)
if ( ! empty( $text ) && in_array( 'meta_key', $categories ) ) { echo '' . esc_html( $text ) . ''; }->meta_key must be the categories name where I want to show the custom field, not the custom field name.
Furthermore I’ve added:
if ( $atts['show_title'] && !in_array( 'trainer', $categories ) ) $entry->getTitleBlock();So the title is always shown except in category “trainer”, and the “mannschaft” custom field is shown only in trainer. Did the trick, perfect!! Thanks
07/04/2016 at 1:11 pm #381462Bene
GuestHm,
just rechecked it, seems to be a little more to do :-)
-> Problem with the solution above is that the title now is never shown if a person is assigned to both categories.
So it is like that:
Category “trainer” list:
Mr.X
Mannschaft: team 1Category “bosses” list:
Mr X
Mannschaft: team 1But I need the following:
Category “trainer” list:
Mr.X
Mannschaft: team 1Category “bosses” list:
Mr X
Title: vice President.So I don’t need the assigned categories of an entry, but the current selected category from the shortcodes…
Thanks in advance
07/04/2016 at 5:26 pm #381482Steven Zahm
Keymaster@ Bene
re: It worked, but I think you mixed something up :-)
Yep, I did :/
the code is right, but change the
meta_keythe Category Slug. You can find these on the Categories admin page.re: So I don’t need the assigned categories of an entry, but the current selected category from the shortcodes…
The shortcode options will be found in the
$attsarray. So the category shortcode option would be found like this:$atts['category']So using the shortcode from your original post, the value would be
4. Does that help you?07/05/2016 at 1:55 am #381515Bene
GuestYes,
I think if I add this to the if-clause then I can switch between the categories.
I will try it this evening.
Thanks a lot for your fast help!!
07/05/2016 at 4:09 pm #381666Bene
GuestWorked perfect: Final code if ( $atts[‘show_title’] && $atts[‘category’] != 3) $entry->getTitleBlock(); and for custom field: $text = $entry->getMeta( array( ‘key’ => ‘mannschaft_id’, ‘single’ => TRUE ) ); if ( ! empty( $text ) && $atts[‘category’] == 3 ) { echo ‘
‘ . esc_html( $text ) . ”; }07/06/2016 at 10:30 am #381750Steven Zahm
Keymaster@ Bene
Great to hear!
If you have a moment, I would truly appreciate a review as they really do make a difference. Many thanks in advance!
https://wordpress.org/support/view/plugin-reviews/connections
-
AuthorPosts
You cannot reply to this support topic. Please open your own support topic.
