engelen
  • Member for 8 years, 3 months
  • Last seen more than a week ago
Why use wp_send_json() over echo json_encode()?
Accepted answer
24 votes

wp_send_json() handles all parts of returning content in an AJAX call. First off, it sets the content type of the returned content to application/json with the proper charset. Secondly, it ...

View answer
Only show content before more tag
Accepted answer
23 votes

You can use the WordPress function get_extended to fetch the different parts of a string (the part before and the part after the <!--more--> tag). get_extended returns an array with three keys, ...

View answer
Slug Formatting : Acceptable Characters?
Accepted answer
14 votes

No, forward slashes are not allowed to be used in slugs. However, they are automatically stripped out when trying to include slashes in a slug on the post editing screen. Slugs are sanitized by using ...

View answer
Using a private method as an action callback from within a class
Accepted answer
11 votes

It's not possible to call a private method through an action or filter. When calling add_action or add_filter, WordPress adds the callback to a list of callbacks for that specific action or filter. ...

View answer
Retrieve a specific field from taxonomy term through advanced custom fields
Accepted answer
8 votes

To retrieve a field from ACF for a term (instead of, for example, a post), you should use the taxonomy name, followed by an underscore, followed by the term ID instead of the post ID when calling ...

View answer
How to query posts of standard post format. For real
7 votes

Since WordPress 4.1, WP_Tax_Query supports the NOT EXISTS operator for taxonomy queries. As a post has the "Standard" format if and only if it has no specified format, this is now the preferred method ...

View answer
Hide the post count behind Post Views (Remove All, Published and Trashed) in Custom Post Type
Accepted answer
7 votes

There is, unfortunately, no "pretty" way to do this (i.e. without using string replacing or rewriting a big chunck of functionality). So, resorting to preg_replace... We'll need to filter the links, ...

View answer
Removing filter dropdown in posts table (in this case Yoast SEO)
Accepted answer
5 votes

These additional dropdowns are added via the restrict_manage_posts action hook. This means the dropdown output isn't filterable, but you can remove the hooked action from Yoast SEO. The filter ...

View answer
How to generate "og:image" meta for Facebook sharing when the image in the post is not featured?
Accepted answer
4 votes

As was already stated, Facebook automatically detects images if the OG image tag is missing. However, in some cases, it might detect other images (e.g. not from your post but from other content). In ...

View answer
Add Bootstrap Classes to Recent Posts Widget
Accepted answer
4 votes

Unfortunately, this isn't quite as easy as you might expect, nor is it properly achievable by using filters. WordPress offers very little hooks for widgets in general, let alone for widget content. ...

View answer
Duplicated CSS files using wp_enqueue_style()
Accepted answer
4 votes

Naming conventions for scripts and styles have always been a difficult issue in WordPress plugins, with many different conventions used and often causing conflicts. I'll try to give my view on this ...

View answer
wp_kses vs wp_strip_all_tags
3 votes

I wouldn't call it a benefit or disadvantage, but more of a difference: wp_strip_all_tags simply strips all tags (except for the allowed tags) but does not delete their content by calling the PHP ...

View answer
get_title without filter(the_title)
Accepted answer
3 votes

There's a few ways to do this, but I would argue that the preferred way is, in general, fetching the post_title attribute from the post object. This does not depend on removing all filters for a ...

View answer
Custom bulk_action
Accepted answer
3 votes

I think the latest major release warrants a new answer to this question, considering the popularity of this question. Since WordPress 4.7 (released December 2016) it is possible to add custom bulk ...

View answer
How to have custom menu Item CSS Classes for wp_page_menu() or wp_list_pages()
3 votes

There is no good filter to add the CSS classes to the anchor (<a>) elements, but as you need it for CSS styling you can use the filter for the <li> elements. This filter is called ...

View answer
Wordpress matching URLs with trailing tildes
3 votes

Let me explain WordPress' processing of a request, and a method to change WordPress' behaviour to accomplish your goals accordingly. Parsing the request When WordPress receives a request, it starts ...

View answer
Deleted pages showing up when querying for child pages
3 votes

Unless there's a very good (usually performance, or, of course, inability of core functions to do what you need) reason to use raw SQL requests to fetch posts and other data in WordPress, you shouldn'...

View answer
What to do when theme and WordPress coding standards conflict?
Accepted answer
3 votes

This is a very subjective question — though a very good and interesting one, and I'll try to provide my personal view on this. In general, you should always try to adhere to the WordPress Coding ...

View answer
Display posts from the same category using next/previous post link
3 votes

The previous_post_link and next_post_link functions both have five parameters: $format: Format string for the link, used to control what comes before and after the link $link: Link text to display $...

View answer
How can I show a different theme for admin users? WP 3.8+
Accepted answer
3 votes

You can use the filter stylesheet: <?php add_filter( 'stylesheet', 'wpse149620_stylesheet' ); function wpse149620_stylesheet( $stylesheet ) { if ( ! is_admin() && current_user_can( '...

View answer
Loop - how to get previous/next post for first/last post?
3 votes

You can loop the slides quite simply: $prev_index = ( $loop->current_post == 0 ) ? count( $loop->posts ) - 1 : $loop->current_post - 1; $next_index = ( $loop->current_post == count( $loop-...

View answer
Ajax returning correct data BUT at wrong place
Accepted answer
3 votes

You are specifying the data type returned from the AJAX call to be JSON. However, the string you're returning ("batman begins") is not in JSON-format. Thus, the jQuery ajax-call will fail. Try passing ...

View answer
Multiple, nested tax_query relation
Accepted answer
3 votes

The cat-parameter is not overwritten by tax_query. Instead, it is added to tax_query. Thus, using 'cat' => -5, the following array is appended to tax_query: ( [taxonomy] => category [...

View answer
Form action unfamiliar
Accepted answer
2 votes

Generally, they will return the same URL, as bloginfo( 'url' ) will call home_url internally with any arguments, and the default first argument ($path) of home_url is the empty string. However, ...

View answer
Fatal error: Call to undefined function the_posts_navigation()
Accepted answer
2 votes

The function the_posts_navigation() was added in WordPress 4.1.0, and will therefore not be available in version 4.0 (which you're using). It's highly advised to keep up to date with the latest ...

View answer
Cannot access elements of json object
Accepted answer
2 votes

The result that is currently returned is raw text, which means data[0] accesses the first element (i.e. character) of the string, which is {. Obviously, you want to turn the returned data into a JSON ...

View answer
Unable To Get Published posts using query_posts
Accepted answer
2 votes

First off, you probably shouldn't be using query_posts, which modifies WordPress' main loop and is unsuited for pretty much any purpose (read When should you use WP_Query vs query_posts() vs get_posts(...

View answer
Plugin Options Array Set to Undefined
Accepted answer
2 votes

WordPress provides a default method, wp_parse_args, to combine a set of default options and a user-defined set of options. This method uses PHP's native array_merge for arrays, but also works when ...

View answer
Custom post type's slug gets wrong when adding a custom meta box
Accepted answer
2 votes

This strange behaviour is very likely to be caused by the additional form tag you're adding. The meta boxes are already encapsulated by a form, so adding one yourself in the meta box callback is ...

View answer
Group WP_Query by meta_key date
Accepted answer
2 votes

A good approach to this would be to first fetch all posts sorted by date, and then group them. As you state the time custom field is in the format Y-m-d, so you can properly sort your posts using ...

View answer