Hi,
I am following the ticket https://toolset.com/forums/topic/limit-the-number-of-posts-submitted-by-registered-customers/#post-368894
1) I have included the custom function on my functions.php:
function u_post_count() {
$user_post_count = count( get_posts( array(
'post_type' => 'Anúncios gratuitos',
'author' => get_current_user_id(),
) ) );
return $user_post_count;
}
2) Registered manually u_post_count on settings, front-end, Functions inside conditional evaluations
3) I put on the cred form the conditional:
[wpv-conditional if="( u_post_content() lt '20' )" ]
<label> test </label>
[/wpv-conditional]
[wpv-conditional if="( u_post_content() gt '20')" ]
<label> test 2</label>
[/wpv-conditional]
I have 11 posts from this type. But nothing happens, it seems that u_post_content() is not called.
Can you help me, please?
Hello,
You will need to use post type slug in the parameter "post_type" of WordPress function get_posts(), for example, the post type "Anúncios gratuitos" is using slug "anuncios-gratuitos", you can modify PHP codes, this line from:
'post_type' => 'Anúncios gratuitos',
To:
'post_type' => 'anuncios-gratuitos',
More help:
https://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters
Hi Luo,
I tried to change the post_type but it still didn´t work.
Since it is a custom codes problem, please provide a test with the same problem, fill below private detail box with login details and FTP access, also point out the problem page URL, and where I can edit you PHP codes, I need a live website to test and debug, thanks
Thanks for the details, I can login into your website, and I have tried to create a page and tested the codes you mentioned above, I can see the problem, it does not work.
And it is abnormal, in case it is a compatibility problem, please try this:
1) deactivate other plugins and switch to wordpress default theme, copy those PHP codes into wordpress default theme folder, file functions.php, and test again
2) If the problem still persists, please provide a database dump file (ZIP file) of your website in below private detail box, also point out the problem page URL, I need to test and debug it in my localhost, thanks
Hi Luo,
I tried to change the function name from u_post_count to quantpost (removing _ from name) that is being called and returning a value. The problem now that it is returning zero value. Could you check again, please?
Thanks in advance
As I mentioned above in my first answer:
https://toolset.com/forums/topic/i-need-help-with-limitting-posts-from-a-user-role/#post-646300
You will need to use post type slug in the parameter "post_type" of WordPress function get_posts(),
You can get the post type slug by editing the post type 'Anúncios gratuitos':
hidden link
find it in the option "Slug (obrigatório)"
And I have checked in your theme file functions.php, there isn't any function with name "quantpost", so I have created another new function with new name "my_u_post_count" in your website, and have done below modification in your website:
1) Edit the file functions.php, add below codes:
function my_u_post_content() {
$user_post_count = count( get_posts( array(
'post_type' => 'anuncio-gratuito',
'author' => get_current_user_id(),
) ) );
return $user_post_count;
}
As you can see, I have only changed the function name
2) Dashboard-> Toolset-> Settings-> Conteúdo de front-end
in option "Funções dentro de avaliações condicionais", add above function name "my_u_post_content"
3) Create a page to test the result:
hidden link
Test it in front-end, it works fine. can you confirm it?
Dear Luo,
It worked fine! Thank you very much!