#  GAP3 Coders Taxonomy Post Order Plugin

A WordPress plugin that allows you to reorder posts based on taxonomy terms with a drag-and-drop interface. The custom order is automatically applied to the frontend queries.

## Features

- **Taxonomy-based Ordering**: Reorder posts within specific taxonomy terms (categories, tags, custom taxonomies)
- **Drag & Drop Interface**: Intuitive admin interface with sortable post lists
- **Automatic Frontend Integration**: Custom order is automatically applied to WordPress queries
- **Multiple Taxonomy Support**: Works with categories, tags, and custom taxonomies
- **Keyboard Accessibility**: Support for keyboard navigation (arrow keys)
- **Auto-save**: Order is saved automatically when you drag and drop
- **Reset Functionality**: Reset to default WordPress order anytime

## Installation

1. Upload the plugin folder to `/wp-content/plugins/`
2. Activate the plugin through the 'Plugins' menu in WordPress
3. Go to 'Post Order' in the admin menu to start reordering posts

## How to Use

1. **Access the Plugin**: Go to WordPress Admin → Post Order
2. **Select Taxonomy**: Choose the taxonomy you want to work with (Category, Tag, etc.)
3. **Select Term**: Choose the specific term within that taxonomy
4. **Reorder Posts**: Drag and drop posts to reorder them
5. **Save**: Order is saved automatically, or click "Save Order" button
6. **View Frontend**: The custom order will be applied to taxonomy archive pages and queries

## How It Works

### Backend
- The plugin creates a custom meta field `_gap3coderstpo_order_{taxonomy}_{term_id}` for each post
- When you reorder posts, it saves the position as a number in this meta field
- The admin interface uses jQuery UI Sortable for drag-and-drop functionality

### Frontend Integration
- The plugin hooks into `pre_get_posts` to modify the main WordPress query
- When viewing taxonomy archive pages, it automatically orders posts by the custom order
- Only applies custom ordering when custom order data exists for that taxonomy term

## Supported Queries

The custom order is automatically applied to:
- Category archive pages (`is_category()`)
- Tag archive pages (`is_tag()`)
- Custom taxonomy archive pages (`is_tax()`)
- Main WordPress queries on these pages

## Technical Details

### File Structure
```
gap3coders-taxonomy-post-order/
├── gap3coders-taxonomy-post-order.php     # Main plugin file
├── templates/
│   └── admin-page.php          # Admin interface template
├── assets/
│   ├── admin.js                # Admin JavaScript
│   ├── admin.css               # Admin styles
│   └── frontend.css            # Frontend styles
└── README.md                   # This file
```

### Database Storage
- Custom order is stored as post meta: `_gap3coderstpo_order_{taxonomy}_{term_id}`
- Meta value is an integer representing the position (1, 2, 3, etc.)
- No additional database tables required

### Hooks Used
- `admin_menu` - Adds admin menu page
- `admin_enqueue_scripts` - Loads admin assets
- `wp_enqueue_scripts` - Loads frontend assets
- `pre_get_posts` - Modifies main query for custom ordering
- `wp_ajax_gap3coderstpo_save_post_order` - Handles AJAX save requests
- `wp_ajax_gap3coderstpo_reset_post_order` - Handles AJAX reset requests

## Customization

### Extending to Custom Post Types
To support custom post types, modify the `get_posts()` calls in the plugin to include your post type:

```php
'post_type' => array('post', 'your_custom_post_type')
```

### Custom Frontend Display
You can add custom styling or indicators by modifying `assets/frontend.css` or adding your own CSS.

### Programmatic Access
To get posts in custom order programmatically:

```php
$posts = get_posts(array(
    'post_type' => 'post',
    'tax_query' => array(
        array(
            'taxonomy' => 'category',
            'field' => 'term_id',
            'terms' => $term_id
        )
    ),
    'meta_key' => '_gap3coderstpo_order_category_' . $term_id,
    'orderby' => 'meta_value_num',
    'order' => 'ASC'
));
```

## Browser Support

- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
- Internet Explorer 11+

## Requirements

- WordPress 4.0+
- PHP 5.6+
- jQuery UI (included with WordPress)

## Security

- All AJAX requests are protected with WordPress nonces
- Input sanitization and validation
- Capability checks for admin access
- No direct file access allowed

## Troubleshooting

### Custom Order Not Showing on Frontend
1. Make sure you've saved the order in the admin
2. Check that you're viewing the correct taxonomy archive page
3. Verify that the theme is using standard WordPress query functions

### Drag and Drop Not Working
1. Check browser console for JavaScript errors
2. Ensure jQuery UI is loaded
3. Try deactivating other plugins that might conflict

### Posts Not Appearing in Admin
1. Make sure posts are assigned to the selected taxonomy term
2. Check that posts are published (not draft)
3. Verify taxonomy and term selection

## License

GPL v2 or later

## Support

For support and feature requests, please contact the plugin developer.