Get parse_query filter to return slug instead of id

taxonomy & term won’t be set (in this case), since query vars are mapped from GET/POST. In other words, $qv[‘large_feature’] = 291 (see wp_edit_posts_query() and WP_Query::get_posts() for the big picture). add_filter( ‘parse_query’,’convert_large_feature_id_to_taxonomy_term_in_query’ ); function convert_large_feature_id_to_taxonomy_term_in_query( $query ) { global $pagenow; $qv =& $query->query_vars; if ( $pagenow == ‘edit.php’ && isset( $qv[‘large_feature’] ) && ctype_digit( $qv[‘large_feature’] … Read more

Extract subdomain and relative address from a url

I encountered a similar requirement, and could not find a ready-made solution for this, so I created a function that is based on the standard PHP function parse_url() and added to this over time to extract everything that I could think of. Below is my code and two examples of the output. This will extract … Read more

Get closest page ID from URL

You should be able to get the current url from $url = add_query_arg(). Then assuming, the structure: www.example.com/page/subpage/news/ID/post you can use preg_match to extract /page/subpage/news. Then it would be simple matter of using get_page_by_path();. If that fails you can then check /page/subpage/ and finally /page.

Check what is at URI (post, archive, etc…)

Retrieve “type” of query from url: Previous suggestions As noted in the linked answer, there’s url_to_postid(). This will just get you the ID of the object at that endpoint. Long story short, this function will only return an ID and then run a new \WP_Query to get the post type object from the DB and … Read more

How to use WordPress (PHP) functions in AngularJS partials files?

What works is calling WP’s Ajax endpoint. Note that it is not the address of your partial, but the fixed WP address for all AJAX calls wp_localize_script(‘handle’, ‘myLocalized’, array( ‘ajaxUrl’ => admin_url( ‘admin-ajax.php’ ) ) ); provides the endpoint adress in the JS object myLocalized. You send all requests to that page and refer to … Read more

Gutenberg Block manipulation: Undo parse_blocks() with serialize_blocks() results in unicode issues

As already described in the comments, many WordPress Gutenberg plugins do not use the strict JSON format as WordPress prescribes… (and poorly documented) So it comes to two problems: Sometimes the data is in a JSON format, which parse_blocks() cannot read. If no change is made here, for example, the value attr will be NULL … Read more

How to parse wordpress options json

The comments and answers are correct, it is no JSON but indeed a serialized array. The reason you’re having trouble unserializing it is because of the quotes inside the serialized data. David Walsh wrote a neat article about this. The problem is that you can’t simply go into the database and remove these single quotes … Read more