How to display the custom fields in the post.php & topic.php  

  RSS

Mister
(@mister)
Member Customer
Joined: 10 months ago
Posts: 19
18/02/2018 3:54 am  

Hello

I want to display the custom fields in the templates "post.php" and "topic.php".
Can you tell me how to achieve inclusion in php because I did not find the solution in the documentation.

Waiting to hear from you

MP


ReplyQuote
Mister
(@mister)
Member Customer
Joined: 10 months ago
Posts: 19
19/02/2018 2:56 am  

Do you have a solution to propose ?


ReplyQuote
Astghik
(@astghik)
Support Team Admin
Joined: 1 year ago
Posts: 1511
19/02/2018 8:38 pm  

Hi Mister,

You can get the field information and display it by using these functions.

For wpForo 1.4.7 and higher versions use this function:

<?php wpforo_user_field( 'field_name' ); ?>

 

For 1.4.6 and lower you only can use wpForo User Custom Fields addon functions:

1. This function gets the field information by userId and fieldname and return it. You can print $fieldValue value anywhere you want.

 

 if (function_exists('wpfucfGetField')) {
$fieldValue = wpfucfGetField($userId, $fieldName);
}

 

2. This function prints the field information by userId and fieldname with before and after html parameters

 

if (function_exists('wpfucfTheField')) {
wpfucfTheField($userId, $fieldName, $before = '', $after = '');
}

ReplyQuote
Mister
(@mister)
Member Customer
Joined: 10 months ago
Posts: 19
20/02/2018 3:41 am  

Thank you for the answer.

So if I understand well to display a custom field called "coupdroit" or "bois" or "nomclub", the function will be written as well :

<?php if (function_exists('wpfucfTheField')) {
wpfucfTheField($userId, $coupdroit, $before = '', $after = '');
} ?>

or

<?php if (function_exists('wpfucfTheField')) {
wpfucfTheField($userId, $bois, $before = '', $after = '');
} ?>

or

<?php if (function_exists('wpfucfTheField')) {
wpfucfTheField($userId, $nomclub, $before = '', $after = '');
} ?>

I tried with these examples but it does not work. I tried with a field included in the plugin with for example "site" but it does not work either.

Can you tell me where my mistake comes from?

thank you in advance

MP


ReplyQuote
Astghik
(@astghik)
Support Team Admin
Joined: 1 year ago
Posts: 1511
23/02/2018 5:05 pm  

For example, for the field "coupdroit" and user with id 15 the functions will be like this. 

if (function_exists('wpfucfGetField')) {
$fieldValue = wpfucfGetField(15, "coupdroit");
}

and

if (function_exists('wpfucfTheField')) {
wpfucfTheField(15, "coupdroit", $before = '<h4>', $after = '</h4>');
}


ReplyQuote
Mister
(@mister)
Member Customer
Joined: 10 months ago
Posts: 19
24/02/2018 1:19 am  

Thank you that works well but only for a user.
How to make the & id value suitable for all forum users?

This information is displayed in the user's information and is displayed in the view of everyone.

Thanks you

Capture d’écran 2018 02 23 à 22.17.04


ReplyQuote
Tom
 Tom
(@tomson)
Support Team Admin
Joined: 4 years ago
Posts: 2784
24/02/2018 3:45 pm  
Posted by: Mister

Thank you that works well but only for a user.
How to make the & id value suitable for all forum users?

This information is displayed in the user's information and is displayed in the view of everyone.

Thanks you

As it's already mentioned this function is only for user with ID=15. You should use $member['userid'] member variable ID instead of 15.

 


ReplyQuote
Mister
(@mister)
Member Customer
Joined: 10 months ago
Posts: 19
25/02/2018 12:01 am  

Ok it's perfect 🙂

Thanks you very much 

MP


ReplyQuote
Faithnall
(@faithnall)
Active Member
Joined: 10 months ago
Posts: 13
17/03/2018 6:08 pm  

Mister, you get it work.
So can you tell me where to add the Lines, the support for this (for me) MAIN Feature is not the best here.

 

I have add the Line Number two for a test in post.php after Line 33:

 <?php wpforo_member_badge($member) ?>
<div class="author-joined"><?php wpforo_phrase('Joined') ?>:<?php wpforo_date($member['user_registered']); ?></div>
<div class="author-posts"><?php wpforo_phrase('Posts') ?>: <?php echo intval($member['posts']) ?></div>
<div class="author-posts"><?php if (function_exists('wpfucfTheField')) {wpfucfTheField($member['userid'], "field_c5a0017", $before = '<h4>', $after = '</h4>');?></div>

But this ends in an error inside the foreach loop.

Next step i try to add the other line befor and after this

 

<? if (function_exists('wpfucfGetField')) {$fieldValue = wpfucfGetField(15, "field_c5a0017");}?>

 

But with the same end. It dos not work.


ReplyQuote
Tom
 Tom
(@tomson)
Support Team Admin
Joined: 4 years ago
Posts: 2784
18/03/2018 1:14 am  

@faithnall, wpForo 1.4.7 is released and you can use core function instead of addon function. Please use this function and set field as the attribute.

<?php wpforo_user_field( 'field_name' ); ?>

 


ReplyQuote
Share: