Determining Slug Before and After Edit

If the post/page was previously published, and you changed the slug when you edited the page, the old slug gets put into the post meta table with the name _wp_old_slug. So you can use get_post_meta( $post->ID, ‘_wp_old_slug’, $single = false ); to retrieve the former slug(s). I see no reason this wouldn’t work with CPTs, … Read more

Adding Post Counts to Menu (Nav) Programmatically?

WordPress’ get_categories() function returns an array of category objects, each of which has a “count” property for the number of posts in that category. So something like this would get you a list of links to category pages: $categories = get_categories(); $markup = ‘<ul>’; foreach( $categories as $category ) { $catName = $category->category_nicename; $count = … Read more

Post Admin – Filter by posts without tags

The first part is to add a dropdown using restrict_manage_posts filter, and the second one is to actually get posts without tags using pre_get_posts filter: function wpse147471_add_no_tags_filter() { if ( ‘post’ !== get_current_screen()->post_type ) { return; } $selected = ( isset( $_GET[‘tag-filter’] ) && ‘no-tags’ === $_GET[‘tag-filter’] ); ?> <select name=”tag-filter”> <option value=””>&mdash; Select &mdash;</option> … Read more

Change padding to text indent in “Increase indent” TinyMCE

You need to modify the TinyMCE settings object on instantiation: Reference: TinyMCE documentation – content formatting WordPress provides a filter for this very purpose called tiny_mce_before_init which you can use as follows: function modify_tinymce_settings($settings) { $settings[‘indentation’] = ’10px’; return $settings; } add_filter(‘tiny_mce_before_init’, ‘modify_tinymce_settings’); If that does not work precisely, then dump the output of $settings … Read more

JSON not valid after json_encode posts

Newlines are not valid inside json strings. However you are outputting this code or otherwise checking it for sanity is somehow adding newlines into your long strings here. Check that your strings really are all one line and not broken up into multiple lines.

WP REST API, query total posts in a category

To just know the number of posts in a category, its endpoint returns that number straightforward, in example: curl http://wired.com/wp-json/wp/v2/categories/24 In the resource returned, the count field says: 486 Which is the same number the metadata says about the total number of posts, if you request the posts in that category, rather than the category … Read more

widget should display post archive by year and on click also by month

I did this for a client and it looked like this: The PHP code: <dl class=”tree-accordion”> <?php $currentyear = date(“Y”); $years = range($currentyear, 1950); foreach($years as $year) { ?> <dt><a href=””><i class=”fa fa-fw fa-plus-square-o” aria-hidden=”true”></i> <?php echo $year; ?></a></dt> <?php $archi = wp_get_archives(‘echo=0&show_post_count=1&type=monthly&year=” . $year); $archi = explode(“</li>’, $archi); $links = array(); foreach($archi as $link) … Read more

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