Sorting posts by custom date fields (non standard date format)

You can add a posts_orderby filter to flip the meta_value: function wpse174075_posts_orderby( $orderby, $query ) { if ( $query->get( ‘orderby’ ) != ‘ddmmyy_date_format’ ) return $orderby; if ( ! ( $order = $query->get( ‘order’ ) ) ) $order=”DESC”; global $wpdb; $mv = $wpdb->postmeta . ‘.meta_value’; // Note SUBSTR() position (2nd) arg is 1-indexed. return ‘CONCAT(SUBSTR(‘ … Read more

Add custom fields within meta box class “on the fly”

Agreed, I’ve seen it too, but I don’t think there’s any readily available API or method. For me, I use a lick of jQuery; <input type=”text” class=”list-item” name=”list_items[]” /> <input type=”button” class=”button-secondary” id=”add-list” /> <script type=”text/javascript”> ( function( $ ) { $( ‘#add-list’ ).click( function() { var $item = $( ‘.list-item:last’ ), $new = $item.clone(); … Read more

Change behavior of “Insert into Post” based on attachment metadata

In case it’s helpful to anyone else, here’s what my code looked like to achieve this. I didn’t end up saving the attachment data at all, per tbuteler’s suggestion, but rather than using $_REQUEST I found I could use the $attachment array directly: function my_attachment_fields_to_edit( $form_fields, $post ) { $supported_exts = supported_types(); // array of … Read more

Hide custom post type field from author?

The easiest way to do that would be to check the capabilities with current_user_can before displaying the field. For instance, the administrator role has the capability manage_options which your newly created users won’t have. So you can do something like this: <?php // wherever your fields are… if(current_user_can(‘manage_options’)) { // display your fields here. } … Read more

Query custom post type by custom field

You got it pretty close. Here’s a working example of what you’re trying to do: class Wpse_126374 { public function __construct() { add_action( ‘init’, array( $this, ‘rewrites’ ) ); add_action( ‘pre_get_posts’, array( $this, ‘pre_get_posts’ ) ); } public function rewrites() { add_rewrite_tag( ‘%parent_id%’, ‘(\d+)’ ); } public function pre_get_posts( $query ) { // Don’t run … Read more

Add custom objects/entities to WordPress

I think what you want is to create what WorpPress calls “Custom Post Types”. Please have a look at the Post Type page in the Codex that explains what Post Types are and how to create custom ones. Basically, here is the code to create the Object custom post type : add_action( ‘init’, ‘create_post_type’ ); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)