How to add the category ID to admin page

The hooks for taxonomies are: “manage_edit-${taxonomy}_columns” for the header “manage_edit-${taxonomy}_sortable_columns” to make columns sortable “manage_${taxonomy}_custom_column” for the cell content To catch all taxonomies write: foreach ( get_taxonomies() as $taxonomy ) { add_action( “manage_edit-${taxonomy}_columns”, ‘t5_add_col’ ); add_filter( “manage_edit-${taxonomy}_sortable_columns”, ‘t5_add_col’ ); add_filter( “manage_${taxonomy}_custom_column”, ‘t5_show_id’, 10, 3 ); } add_action( ‘admin_print_styles-edit-tags.php’, ‘t5_tax_id_style’ ); function t5_add_col( $columns ) { … Read more

Get page id by title?

There is a function exactly for that: get_page_by_title( $page_title, $output = OBJECT, $post_type=”page” ); You can use it like this: $page = get_page_by_title( ‘Start’ ); To get the page from a specific post type: $custom = get_page_by_title( ‘Start’, OBJECT, ‘your_custom_post_type’ ); $post = get_page_by_title( ‘Start’, OBJECT, ‘post’ ); Be aware, this function will search in … Read more

Get ID of “root-page”

I think what you need is: <?php $post_id = $post->ID; //or somehow get the current post ID. $ancestors = get_post_ancestors($post_id) //$ancestors is an array of post IDs starting with the current post going up the root //’Pop’ the root ancestor out or returns the current ID if the post has no ancestors. $root_id = (!empty($ancestors) … Read more

Categories id Tags

ID for posts/blogs page

consider to use: $postspage_id = get_option(‘page_for_posts’); and then change the rspective line in your code to: $leftSidebar = get_post_meta( $postspage_id, ‘_my_meta’, true ); from: http://www.blog.highub.com/cms/wordpress/wordpress-front-page-posts-page-id/

Can’t get post ID in functions.php?

The post ID is available after the query has been fired. The first hook that is safe to get post id is ‘template_redirect’. If you can modify your function to accept a post id as argument, like so: function em_change_form($id){ $reg_type = filter_input(INPUT_GET, ‘reg_typ’, FILTER_SANITIZE_STRING); if($reg_type === ‘vln’){ update_post_meta($id,’custom_booking_form’, 2); } elseif ($reg_type == ‘rsvp’) … Read more

Get the current post ID as a variable in Javascript

You can pass variables to javascript using wp_localize_script function: https://codex.wordpress.org/Function_Reference/wp_localize_script Add the following to functions.php if(!function_exists(‘load_my_script’)){ function load_my_script() { global $post; $deps = array(‘jquery’); $version= ‘1.0’; $in_footer = true; wp_enqueue_script(‘my-script’, get_stylesheet_directory_uri() . ‘/js/my-script.js’, $deps, $version, $in_footer); wp_localize_script(‘my-script’, ‘my_script_vars’, array( ‘postID’ => $post->ID ) ); } } add_action(‘wp_enqueue_scripts’, ‘load_my_script’); And your js file (theme-name/js/my-script.js): jQuery(document).ready(function($) { … Read more

Settings API – creating reusable form elements?

You’re absolutely right that you can pass reusable form field markup to add_settings_field(). The trick is to define the data type for each setting, and then pass the same callback to each call to add_settings_field(). Within that callback, you simply add a switch that includes cases for each data type. Here’s how I do it … Read more

What is an alternative to get_page_by_title()?

If you don’t force a title, and obviously do not know the id, the only way you can do it is by letting the user select which page to use, usually done in the theme’s options page, but can be done in the costumizer, or even as part of page editing

Creating a WordPress admin page without a menu for a plugin

I am less convinced that I know what you are doing than I once was. // Add menu and pages to WordPress admin area add_action(‘admin_menu’, ‘myplugin_create_top_level_menu’); function myplugin_create_top_level_menu() { // This is the menu on the side add_menu_page( ‘MyPlugin’, ‘MyPlugin’, ‘manage_options’, ‘myplugin-top-level-page’ ); // This is the first page that is displayed when the menu … Read more

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