Here it is my solution:
1: In order to get sub catebories, I played around with tags and I was able to create a system where I could show only tags attached to posts within a specific category, this will act as some sort of “sub category”. In the user submit posts plugin, find the file called: submission-form.php, this is the file we’ll edit. Just below <?php } if ($usp_options['usp_tags'] == 'show') { ?>
we do the following:
First: Get the cat id:
$cat=5;
$yourcat = get_category($cat);
if ($yourcat) {
echo '<h3>' . $yourcat->name . '</h3>';
}
Then we loop all tags and we output it in a list and we make sure we don’t have any duplicates:
<ul>
query_posts('category_name=Ambiente');
if (have_posts()) {
$allTags = array();
while (have_posts()) {
the_post();
if( get_the_tag_list() ) {
$tags = wp_get_post_tags( get_the_ID());
foreach($tags as $tag) {
$allTags[$tag->name] = $tag;
}
}
}
foreach($allTags as $tag) {
echo '<li><input class="checkTag" type="checkbox" value="' . $tag->name . '" />' . '??' . $tag->name . '</li>';
}
}
wp_reset_query();
?>
</ul>
Just repeat this for all your category and change the category id.
Note: I am using:
echo '<li><input class="checkTag" type="checkbox" value="' . $tag->name . '" />' . '??' . $tag->name . '</li>';
Display a list of tags based on category and have a checkbox next to each tag, this is because I am saying to the user: “Hey look all tags already created for each category, maybe you find one you like, if so, check it and the input field for the tag will be automatically populated.
Using this jQuery in the footer to be able to automatically insert in the tag input field the same as what it is writtent next to the check box:
$('.checkTag').click(function() {
$("#user-submitted-tags").val(
$('.checkTag:checked').map(function() {
return $(this).val();
}).get().join(', ')
);
});
With that, the selected checkbox will populate the tag input field, you can select multiple checkboxes too, and the tags will be written in the input field with a comma for multiple tags selection.
Note: There maybe tons of tags (subcategories), so what I did was to insert a link “Check all existing sub-categories => click > a pop up opens with all the lists. In my case I have used bootstrap3 modal
If the user wants to create a new sub-category (a tag), they won’t select any checkbox and can simply write it in the input field as normal:
<input name="user-submitted-tags" required id="user-submitted-tags" data-required="true" type="text" value="" placeholder="Scrivi la sottocategoria" class="form-control input-lg usp-input">
Careful to the classes I have used as these are used in the jQuery bit too.
Done! Now we treates tags as some sort of sub category.
—
The authors:
The plugin is great and you don’t need to register, which means the posts will be written with whatever name you provide but actually wordpress thinks they are written by the admin with just a differnt name. So What I had to do was to get the author name and with the following I am able to:
1: Get the author and display all posts made by it
2: Get the total number of posts the author made
3: Get a link to each posts it made
<ul>
<?php
$args= array(
'posts_per_page' => -1
);
query_posts($args);
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li>
<?php
$args = array(
'posts_per_page' => -1,
'meta_key' => 'user_submit_name',
'meta_value' => get_the_author(),
'meta_compare' => '='
);
$myquery = new WP_Query($args);
echo '<h3>' . $myquery->found_posts . ' proposte da ' . get_the_author() . '</h3>';
while ( $myquery->have_posts() ) {
$myquery->the_post();
echo '</li>
<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>
';
}
?>
<?php wp_reset_postdata(); ?>
<?php endwhile; ?> <?php endif; ?>
</ul>
Done!
The last bit I will do is to ask the user to insert their name and I will attach a random unique string, then tell the user to always use that username when posting in order to not have duplcate username and therefore be able to really show all posts made by 1 author.
e.g.
User 1 says: My name is => Simon, and he writes a post
User 2 says: My name is => Simon, and he writes a post.
As we can see they are 2 users using the same name, which makes it impossible di distinguish the 2 different authors.
The solution I am thinking is as I said, create a unique string which will be attached to the Name provided by the user, and just tell them to always use that username when posting. E.g.
simon_uniquexyz
simon_uniquegtd
I hope this will help someone.