Home How to pass number of posts in category to input upon choosing category from select in wordpress?
Reply: 0

How to pass number of posts in category to input upon choosing category from select in wordpress?

Korovjov
1#
Korovjov Published in 2017-12-07 18:09:36Z

I have made simple front end post creator in wordpress, via form. On the end of post user is prompted to select the category, and based on users selection, the number of posts of this very category should be passed to input and incremented by 1. (I am trying to make some kind of numeration, lake page number, or something, because it is more than important to my customer to have this.).

<select name="event-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> 
<option value=""><?php echo esc_attr(__('Select Category')); ?></option> 

<?php 
    $option = '<option value="' . get_option('home') . '/category/">All Categories</option>'; // change category to your custom page slug
    $categories = get_categories(); 
    foreach ($categories as $category) {
        $option .= '<option value="'.get_option('home').'/category/'.$category->slug.'">';
        $option .= $category->cat_name;
        $option .= ' ('.$category->category_count.')';
        $option .= '</option>';
    }
    echo $option;
?>

So basically from this I have to pass the number of posts to simple and increment it by one.

I have tried to use jQuery to read the select and than choose only number and pass it, but it did not work...

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.545636 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO