Tag Info

Hot answers tagged

7

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 in Oenology: First, I dynamically ...


7

Try this... add_action('post_updated', 'myfunction'); function myfunction( $post_id ) { global $post; if (!file_exists("/www/foo/blog/wp-content/uploads/" . $post_id)) { mkdir("/www/foo/blog/wp-content/uploads/" . $post_id, 0777); } } NOTE: Change from save_posts to post_updated which will stop the duplicate issue as it ...


5

Because the tag query variable expects the value to the terms slug. It'll be looking for the term with slug '15' (which presumably doesn't exist). And, yes its quite frustrating that wp_dropdown_categories() uses the ID as the value, rather than the slug. This is because it was originally used only for categories (for which IDs rather than slugs are ...


5

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/


4

The simplest and most straightforward way to get the post author ID outside the loop, if you know the post ID, is to use the WordPress core function get_post_field(). $post_author_id = get_post_field( 'post_author', $post_id ); If you do not yet know the post ID of the page you are on, then since WP 3.1 the easiest thing to do is use the ...


4

The thing to remember about get_posts is that is uses a WP_Query object internally. get_posts source: <?php /** * Retrieve list of latest posts or posts matching criteria. * * The defaults are as follows: * 'numberposts' - Default is 5. Total number of posts to retrieve. * 'offset' - Default is 0. See {@link WP_Query::query()} for more. * ...


4

Menu items are stored in the posts table with a post_type of nav_menu_item. So, what you are returning is the ID of the menu item itself, not what it points to. The page/post ID that the menu item refers to is stored in the postmeta table, with a post_id that matches the menu item ID and meta_key = _menu_item_object_id. The easiest way to get the meta_value ...


4

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 ...


4

On that page $post->ID returns the ID of first blog post for given page. That is how it works. $post is set to the first post in the Loop. On single posts and pages that is the same as the post or page. On archive pages it is the first post in the result set. And if you think about that, both are really the same thing. Single posts and pages only have ...


4

The following query retrieves the oldest post of a specified user/author: $user_id = 42; // or whatever it is $args = array( 'posts_per_page' => 1, 'post_status' => 'publish', 'author' => $user_id, 'orderby' => 'date', 'order' => 'ASC', ); $first_post = new WP_Query($args); if ($first_post->have_posts()) { ...


3

As you haven't offered the details on what you're after, I'll try to grab them all very briefly. Use the API - public WP_User_Query API functions Basically get_user_by() should be enough for you. Let's say you fire of your form and the input field name was user_id. So you'd just retrieve the value from the $_REQUEST (or $_GET) and then do a simple query. ...


3

I had a similar problem and solved it by using a static variable inside the class: static protected $menu_lvl; And then in the "display_element" I incremented the variable: self::$menu_lvl++; In my code I then referenced in the start_lvl function something like this: $output .= "<ul id='level". self::$menu_lvl ."'>"; This doesn't use the page ...


3

I just had to do this in one of my themes... Since you don't have access to the $item variable at that stage of the Walker, you would want to store your current item in a more global scope when you do have access to it. The following code will make more sense... note: I've stripped everything but the relevant code. class ThemeTruck_Nav_Walker extends ...


3

Here’s how to obtain and get the author ID outside the WordPress loop: <?php global $post; $author_id=$post->post_author; ?> Then it is possible to us the_author_meta: <?php the_author_meta( 'user_nicename', $author_id ); ?>


3

Read the Codex, Look at the function in the core file, Modify your code as follows: function myFunc( $post ) { $postID = $post->ID; } The post transistion does not send the post ID, it sends the complete post object. Sometimes a simple die(var_dump($postID)); (or whatever you use as parameter) helps to find out what will be send to the ...


3

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) ? ...


3

I'm not sure how to get it via the title, but you can get it via the slug (which is often more useful in my experience) using this: http://erikt.tumblr.com/post/278953342/get-a-wordpress-page-id-with-the-slug Just change "$page" to "$post" if you want to return slugs for posts instead of pages. G'luck!


3

In the following, '10' is the priority that my_func gets called and '2' is the number of arguments that my_func accepts. The latter is important, since the add_filter function defines the default as 1, but the wp_insert_post_data filter hook sends two arguments. If you don't set this as 2 you won't get the second argument. add_filter("wp_insert_post_data", ...


3

You are probably looking for the user_exists function. http://codex.wordpress.org/Function_Reference/email_exists This function will check whether or not a given email address ($email) has already been registered to a username, and returns that users ID (or false if none exists). If the email address does not exist (user_exists returns false), you may ...


2

First, you don't need the apply_filters below. That is called directly from the wp_mime_type_icon() function already. The issue is that your add_filter() call is missing the $accepted_args parameter. The add_filter() function has the following construct: add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) So the $accepted_args is 1 ...


2

Break this down into two parts: First, we create a variable that stores that last-visited page URL, like this: $prev_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; Then, you could either use substr and strpos to trim down everything between ?= and the / after the ID number. like this: $prev_url = 'http://www.yoursite.com/?p=123'; ...


2

The global $post object is from the current query, so what you're seeing is the expected behavior. If you always want the shortcode to return the post_meta from ID = 1, then you should just hardcode that into the shortcode like in @Chris_O's answer where you just save a variable that equals 1 and pass that to get_page(). However, it sounds like you're ...


2

I do not see any problem in your query (except some poor query writing styles). You did not explain 'does not work'. what you get in return? do you get any errors? Probably you do not have any published job_listing! However, here is how you can improve your given code: $oldest_post_id = $wpdb->get_row("SELECT `id` FROM {$wpdb->posts} WHERE ...


2

Depends on where you are. If you're on a singular page (eg. only showing a single {{Insert Post Type Here}}), you could use get_queried_object, which will fetch the post object. <?php if (is_singular()) { $author_id = get_queried_object()->post_author; $address = get_the_author_meta('user_email', $author_id); } If you're anywhere else, you ...


2

This is normal behaviour, as I understand it. When you load the page post-new.php, you run this function: $post = get_default_post_to_edit( $post_type, true ); where the second argument stands for $create_in_db. If true then this part is executed: if ( $create_in_db ) { $post_id = wp_insert_post(...); } inside get_default_post_to_edit().


2

You are assigning the attachment URL to your $url variable: $url = wp_get_attachment_url( get_post_thumbnail_id( $id ) ); then passing that same variable back to wp_get_attachment_url: return '<img src="' . wp_get_attachment_url( $url ) . '"/><a href="' . get_permalink( $id ) . '">' . get_the_title( $id ) . '</a>'; You should simply ...


2

There is a global variable called … $user_id available on that page. Always. From user-edit.php: $user_id = (int) $user_id; $current_user = wp_get_current_user(); if ( ! defined( 'IS_PROFILE_PAGE' ) ) define( 'IS_PROFILE_PAGE', ( $user_id == $current_user->ID ) ); if ( ! $user_id && IS_PROFILE_PAGE ) $user_id = $current_user->ID; ...


2

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' ); ...


2

get_page_by_path() should help you here. Something like this <php $prev_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; if ( $prev_url ) { $prev_path = str_replace( home_url(), '', $prev_url ); $page = get_page_by_path( $prev_path ); } That should give you the page object, where you can access it's ID like so - ...


2

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', ...



Only top voted, non community-wiki answers of a minimum length are eligible