Getting Position of a post in a category

If I understand well, you need to retrieve all the posts having category ‘y’ and also meta key ‘facebook_shares’, after that, you need the position of a specific post. My proposal is: Create a class that extends WP_Query and filter the results for required category and meta field. This class should also filter the SQL … Read more

Permanently remove first image from posts

Just as @s_ha_dum suggests, you can loop through all of your posts and update the content of each one. The following gives you the idea but is untested: $posts = get_posts( array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 500, ‘offset’ => 0, ) ); foreach( $posts as $post ): // Update each post with your reg-ex … Read more

How can you make sure authors’ posts are longer than 250 words?

Prevent authors from publishing too short content: Here’s one idea using a custom post status, for example short: /** * Register a custom ‘short’ post status * * @see http://wordpress.stackexchange.com/a/159044/26350 */ function wpse_short_post_status() { register_post_status( ‘short’, array( ‘label’ => _x( ‘Short’, ‘post’ ), ‘public’ => false, ‘exclude_from_search’ => true, ‘show_in_admin_all_list’ => true, ‘show_in_admin_status_list’ => true, … Read more

How do you get all the urls of images attached to a post?

You need to loop through the attachments within your post loop, replace the section of code you posted with this (put this together from some other code I found related to a similar problem, but couldn’t test it): </BasicDetails> <?php $args = array( ‘post_parent’ => $post->ID, ‘post_type’ => ‘attachment’, ‘numberposts’ => -1, // show all … Read more

Alter query on edit.php

Few days ago I wrote a quick solution using pre_get_posts filter to hide some pages in admin area. Maybe you could use it as a good starting point for whatever you’d like to achieve. if ( is_admin() ) add_filter(‘pre_get_posts’, ‘mau_filter_admin_pages’); function mau_filter_admin_pages($query) { $query->set(‘post__not_in’, array(1,2,3) ); // Do not display posts with IDs 1, 2 … Read more

Plain-text tag list?

You can play with arguments to only fetch what you need and get rid of loop: $classes = implode(‘ ‘, wp_get_post_tags( get_the_ID(), array(‘fields’ => ‘names’) ) );

Query posts from current year

You just need get current date and add it on data_query in wp_query, Look this: <?php $getdate = getdate(); $args = array( ‘date_query’ => array( array( ‘year’ => $getdate[“year”] ), ), ); $query = new WP_Query( $args ); ?> and then use loop: <?php if ( $query->have_posts() ): while ( $query->have_posts() ) : $query->the_post(); the_title(); … Read more

post_name empty after wp_insert_post

Firstly, you shouldn’t use post_category, because according to the wordpress codex wp_insert_post(): ‘post_category’ => [ array(, <…>) ] //post_category no longer exists, try wp_set_post_terms() for setting a post’s categories Secondly, if you want the post title to be your slug you shouldn’t need to use the post_name parameter, because it gets constructed from the title … Read more

Add metabox with media uploader in a custom post type [duplicate]

I am working on something similar. This is for a podcast upload meta-box. Returns the url to the file. Here is what I have so far: //Add Metabox add_action(‘add_meta_boxes’, ‘add_upload_file_metaboxes’); function add_upload_file_metaboxes() { add_meta_box(‘swp_file_upload’, ‘File Upload’, ‘swp_file_upload’, ‘podcasts’, ‘normal’, ‘default’); } function swp_file_upload() { global $post; // Noncename needed to verify where the data originated … Read more

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