Hot answers tagged

2

This little snippet could help you. $years = array(); if( have_posts() ) { while( have_posts() ) { the_post(); $year = get_the_date( 'Y' ); if ( ! isset( $years[ $year ] ) ) $years[ $year ] = array(); $years[ $year ][] = array( 'title' => get_the_title(), 'permalink' => get_the_permalink() ); } } This code gets ...


1

image_send_to_editor hook will handle when the image is sent to the editor. The problem will be that your editor may not work correctly when you modify the URL -- use with caution. save_post will allow you to modify the $post content on save. update_(meta_type)_metadata could be used to intercept when the meta data is saved.


1

Suppose you haven't modified anything to change the default content output, maybe this can help: add_filter('the_content', function($content) { $content = preg_replace('~^<p><img([^>]+)></p>~i', '', $content, 1); return $content; }, PHP_INT_MAX);


1

The below code check that post have category or not. If post have category then it will display list of category separate by comma. You can try this code. Hope this will help you. if(has_category()) { echo $cats_list = get_the_category_list(', '); }


1

In general the answer is yes and the web is full of good tutorials that would do a better job than I can here.


1

Sadly the stock wordpress doesn't give much more help with custom fields. I'd recommend using the advanced custom fields plugin. https://wordpress.org/plugins/advanced-custom-fields/ You can set the name when creating a field and match it to what you've been using and it should work retroactively on old posts and content as well.


1

You can calculate offset via paged and posts_per_page. E.g: $per_page = 6; $paged = get_query_var('paged', 1); $offset = (1 === $paged) ? 0 : (($paged - 1) * $per_page) + 2; $args = array( 'order' => 'ASC', 'paged' => $paged, 'offset' => $offset, 'orderby' => 'ID', 'post_type' => 'post', 'post_status' => 'publish', '...


1

to use a translation not finished yet, click on "Export" here : https://translate.wordpress.org/projects/wp/dev/si/default . And save the files as si.po and si.mo in the directory wp-content/languages (choose the extension in the dropbox menu) If there is word missing, you can use Podedit to edit the file and you can also propose your word in the tool ...


1

You can use get_term_by to get a category by name- $category = get_term_by( 'name', $post_slug, 'category' ); echo $category->term_id;


1

That is because you're trying to define a property that is already defined, query a table with a wrong name, loop through an integer while you can use get_results instead of query method of $wpdb ... I edited the code, hope it will help with your post duplication process: defined('WP_USE_THEMES') || define('WP_USE_THEMES', false); require_once('wp-load.php'...


1

First, I would use WP_Query instead of the manual DB query (and don't tell me that's because of performance because you're querying 2 times the same thing). Second, you're saving your post as draft status and querying post with status publish


1

There is no Page attributes because it's not a page and by default WordPress doesn't have an attribute to select template for post. The page templates are coded in the theme that you are using.It seems that the theme has a template called Full Width defined as page template so you are able to select it for pages. To not display the sidebar in the single ...


1

This is a partial answer, because as I mentioned in my comment I'm not sure why your code is requiring two 'really bad words' at the moment. It's also an untested attempt. I'll deal with your first question: how to send a user back to the posts page and display a suitable error message, rather than an error about editing posts in the trash. A way to do ...


1

Here's a more readable version of the solution provided by Michael <?php $posts = new WP_Query(array('posts_per_page' => -1)); if ($posts->have_posts()): ?> <ul id="archives"> <?php $prev_month = ''; while ($posts->have_posts()): $posts->the_post(); if (get_the_date('F Y') != $prev_month): $...



Only top voted, non community-wiki answers of a minimum length are eligible