Get the object ID by URL
Try this function: url_to_postid( $url ); The WordPress codex is your friend. A quick Google search could have provided the answer.
Try this function: url_to_postid( $url ); The WordPress codex is your friend. A quick Google search could have provided the answer.
MOST IMPORTANT EDIT When I tested your code, I always added the page header name, and never realized that this was one thing that you didn’t add. You should always name a custom page template so that wordpress knows it’s a page template. So you need to edit your custom page template and add the … Read more
They are filtered via the views_[screen-id] filter. The screen-id of the edit post page is edit-post, so you can modify the links like this: add_action( ‘views_edit-post’, ‘wpse17484_views_edit_post’ ); function wpse17484_views_edit_post( $views ) { $views[‘wpse17484’] = ‘<a href=”https://wordpress.stackexchange.com/questions/17484/my-url”>My action</a>’; return $views; } You can see the code that generates the post views in WP_Posts_List_Table::get_views().
Your problem i believe are the lines that follow the enqueues and print scripts, you’re mixing Javascript with PHP.. Javascript goes inside the HTML section of a PHP file or inside an echo statement. This page of the codex gives an example for adding a button to TinyMCE inside WordPress. However that codex entry might … Read more
Your function doesn’t return a value, so you are effectively wiping the existing states. Also, this hook passes you the current post as an object, so you can use that instead of the global $post. Additionally get_page_template_slug returns a path that is relative to your theme’s root, so if your theme directory is called Lef-en-Liefde … Read more
Use a custom SQL query to grab the latest 16 post IDs with unique authors; $post_IDs = $wpdb->get_col( “SELECT ID FROM $wpdb->posts WHERE post_type=”product” AND post_status=”publish” GROUP BY post_author ORDER BY post_date DESC LIMIT 16″ ); Then start up a new query with the post__in argument; $recent_posts = new WP_Query( array( ‘post__in’ => $post_IDs, ‘post_type’ … Read more
(Revised answer to properly address the questions in the question..) For Question 1 (JS) How can I get a post object from a custom REST endpoint within a Gutenberg block? So there’s the apiFetch() which you can use to fetch resources from the REST API. But unlike return { children: getEntityRecords() }, return { children: … Read more
First, some comments on your code: the globals $post and $wpdb are not needed, in any case you can declare them as global $post, $wpdb; I don’t understand your use of this conditional if (is_null($imgID)) you’re using get_term_by with “slug”, but I guess it’s better to do it by “name” The following is a working … Read more
Slight change in your code, function wpse_custom_field_on_publish( $new, $old, $post ) { // Only run on “from X > to publish”-transitions if ( $new === ‘publish’ && $old !== ‘publish’) { $page_views = get_post_meta( $post->ID, ‘post_views_count’, true ); // Only set ‘post_views_count’ post meta value if there is none so far if ( empty( $page_views … Read more
Ok! @Kieran and @Rarst, here it is 🙂 function stoppostedition_filter( $capauser, $capask, $param){ global $wpdb; $post = get_post( $param[2] ); if( $post->post_status == ‘publish’ ){ // Disable post edit only for authore role if( $capauser[‘author’] == 1 ){ if( ( $param[0] == “edit_post”) || ( $param[0] == “delete_post” ) ) { // How much time … Read more