26

Try this code. $author = get_user_by( 'slug', get_query_var( 'author_name' ) ); echo $author->ID; Alternatively, if author name has not been set use: if ( $author_id = get_query_var( 'author' ) ) { $author = get_user_by( 'id', $author_id ); } credit @AndyAdams in the easily missed comments bellow


24

When your going through your loop add this: global $post; $post = get_post( $ID, OBJECT ); setup_postdata( $post ); //Do something wp_reset_postdata();


9

There's a good chance your HTML is not included in the loop. Make sure your code looks like this: if(have_posts()): while(have_posts()): the_post(); ?> <div class="publication-info"> <?php printf("<h2>%s</h2>", get_the_title() ); ?> <div class="publication-meta publication-credit"><?php ...


9

I would recommend you use home_url() to get the URL to the front page of the currently viewed site. If you want to get the main site URL (the network home), use network_home_url().


7

Yes, as you - so far - have no publish date. You could use $post->post_modified, which will always be the date of the latest modification to the post data. Debug: Try hooking into the filter and dump both vars: function date_dump_callback( $date, $d ) { echo '<pre>'; print_r( $date ); print_r( $d ); echo '</pre>'; return $date; } ...


7

First you need to get all the assigned tag id:s by calling wp_get_post_tags because the include parameter in wp_tag_cloud only works with tags id, Not page id. So when you have all the id:s put them in the include parameter within the wp_tag_cloud like this: <?php // Get the assigned tag_id $tag_ids = wp_get_post_tags( $post->ID, array( '...


7

Yep, wp_trim_words(): <?php $trimmed = wp_trim_words( $text, $num_words = 55, $more = null ); ?> Or in your case: <?php echo apply_filters( 'the_content', wp_trim_words( strip_tags( $post->post_content ), 55 ) ); ?>


6

Since editor displays projected permalink for slug editor, it must have some way to figure it out. From looking at source that is handled by get_sample_permalink_html() and get_sample_permalink(). Since we only need link without form cruft, we can rework it into something like: function get_draft_permalink( $post_id ) { require_once ABSPATH . '/wp-...


5

This is a little "hacky", but when you call get_permalink and you need the permalink for a draft, provide a clone of your post object with the details filled in: global $post; if ( in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) { $my_post = clone $post; $my_post->post_status = 'publish'; $my_post->post_name =...


5

Check for global variable $wp_customize: if ( empty ( $GLOBALS['wp_customize'] ) ) { // show something } Update: in WordPress 4.0, you can use is_customize_preview().


4

post_password_required(): whether post requires password and correct password has been provided. <?php if ( post_password_required() ) { echo 'xxx'; } else { echo 'zzz'; }


4

The Codex page for is_single should be updated, what you're seeing is correct behavior. According to the main Conditional Tags Codex page: is_single() When any single Post (or attachment, or custom Post Type) page is being displayed. (False for Pages) You can exclude attachments by also checking ! is_attachment(). Also, you may want to move that ...


4

<?php echo get_bloginfo( 'url' )?> was exactly was I was looking for.


4

Is there a specific reason to use get_parent_theme_file_path() over get_template_directory() Yes. This new function comes with a filter Filter parent_theme_file_path And argument to the file path If you take a look at the get_parent_theme_file_path() source, it's just returning get_template_directory() with extra functionality like if a file is given as ...


3

Try this simply code if (is_author()){ $author = get_queried_object(); $author_id = $author->ID; }


3

To work with posts outta loop try using: get_post(post_id) to get a post with a specific ID out of the loop,when you do this,the global object $post will hold the post which you'v just selected.Now you can get the content using : $post->post_content . check the get_post documentation on Wordpress Codex


3

Some post-related data is not available to get_posts by default, such as post content through the_content(), or the numeric ID. This is resolved by calling an internal function setup_postdata(), with the $post array as its argument: <?php $args = array( 'posts_per_page' => 3 ); $lastposts = get_posts( $args ); foreach ( $lastposts as $post ) : ...


3

wp_list_categories() is a simple function that returns (or echos, depending on parameter) a list of links to category archives. It needs not to be reset. When you create a new instance of the WP_Query class you need to reset postdata, because Template Tags otherwise use that query and not the main query. You've said: I'm using two of these queries (with ...


3

I'm not sure why it is modifying the data like that when displaying, but you can use $post->post_date_gmt This will return the scheduled post date the same as it is in the DB except it's in GMT time format, so you might need to convert the time to your local time zone first (this blog post may help). Otherwise, you should be able to use it as is if you'...


3

'p' is for querying a post, as opposed to 'page_id' for querying a page. It's documented in the WP_Query codex


3

A template tag is just a function, so I can't understand the difference from a function in functions.php and a template tag. So the choiches are 2: function VS file. The right choice depend case by case, and all things @shazzad pointed found me agree. I prefer use file and get_template_part when the code need to contain a lot of html, because I don't like ...


2

Try adding the global $more variable before you call the_content(). e.g.: <?php global $more; $more = 0; the_content( 'Read More' ); ?> (This is how you enable the "Read More" tag for Pages.)


2

Even if your image doesn't cover the typical full-width area you're used to seeing in twentyten and twentyeleven, add_custom_image_header is the appropriate way to do this, and it's far simpler to use the built-in functionality than building a new options panel to handle it. In the process of declaring support for custom headers, you define the height and ...


2

I just finished posting this My Options Panel a couple of hours a ago which will answers you question.


2

Ok, if you take a look at implementation of is_front_page, you will see the following: /** * Is the query for the front page of the site? * * This is for what is displayed at your site's main URL. * * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_on_front'. * * If you set a static page for the front page of ...


2

To specifically target single items of a particular post type use is_singular(): if( is_singular( 'post' ) ) { // Only execute this block on a single page for a post with type 'post' }


2

get_term_by() might help you here. $tag = get_term_by('id', 12, 'post_tag'); //or whatever taxonomy you are using echo $tag->name;


2

Check out get_next_post_sort and get_previous_post_sort filters. You can modify the ORDER BY clause to whatever you want (including ). For example, if you want to sort the 'next post' to be the post with the smallest adjacent post ID: function wp28041_get_next_post_sort($where){ return 'ORDER BY ID ASC LIMIT 1'; } add_filter('get_next_post_sort', '...


2

First line of the codex for get_content: Displays the contents of the current post. This template tag must be within The_Loop. Also, this line: <meta property="og:description" content="<?php string_limit_words(the_content(), 15);" ?> /> would need to get_the_content(), as the_content() will output, and you need to return. <meta ...


2

Alternatively global $wp_customize; if (isset($wp_customize)) { // do stuff }


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