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


7

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


6

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/


6

<?php if(count($related)) { echo "<div>Read More<ul>"; foreach($related as $id) { echo '<li><a href="'.get_permalink( $id ).'">'.get_the_title( $id ).'</a></li>';     }     echo "</ul></div>";   } ?>  


5

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


5

Use the page_for_posts option: <?php $page_for_posts = get_option( 'page_for_posts' ); ?> This will return the ID of the Page assigned to display the Blog Posts Index.


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


4

Answer: as of 3.3 and beyond, a "problem" structure now only adds one single optimized query. I wrote a post about that, in fact. Bottom line: it's no longer an issue. You're welcome. ;)


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

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


4

Try this code. $author = get_user_by( 'slug', get_query_var( 'author_name' ) ); echo $author->ID;


4

Use get_page_by_path($page_path): $page = get_page_by_path( 'about' ); echo get_the_title( $page ); This will return a regular post object.


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 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 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()) { ...


4

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


4

You are overwriting $post_ids variable on every while loop, never collecting them. That can be solved using $post_ids = array(); while (have_posts()) : the_post(); $post_ids[] = get_the_ID(); endwhile; var_dump($post_ids); // this is an array of ids However there is simpler way, you can skip the whle cycle and simply run: if( function_exists( ...


3

You can use the function get_term_by and use 'name' in the field param. <?php get_term_by( $field, $value, $taxonomy, $output, $filter ) ?> Example: $term = get_term_by('name', 'Social Network', 'nav_menu'); $menu_id = $term->term_id; Here is the link to the codex page: http://codex.wordpress.org/Function_Reference/get_term_by Hope this ...


3

$cat_id = get_queried_object_id(); - it's that simple!


3

Couldn't you use: http://codex.wordpress.org/Function_Reference/get_user_by


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


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

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

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

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


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



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