Tag Info

Hot answers tagged

3

Some of the code in OP is a bit old and depreciated, like caller_get_posts which was depreciated years ago. The correct parameter to use now is ignore_sticky_posts. Your query is also really inefficient and not good for performance. Here is how I would tackle this issue Use get_queried_object_id() to get the current post ID instead of the more unreliable ...


3

There is not wp_undelete_post. You have to use any of these funcitons: wp_publish_post: if you want to move from trash to publish status. wp_update_post: to move from trash to any other status. For example, for a given post ID (of any post type, including pages): if( get_post_status( $post_ID ) == "trash" ) { wp_update_post( array( ...


2

WordPress has built-in support for posting via email. Go to Settings > Writing in your admin and enter your credentials under "Post via e-mail". Note it won't handle Gmail labels (it only works via POP3).


2

You can use the capabilities API to conditionally set screen options: if ( current_user_can( 'manage_options' ) ) { // Administrator, add some options } else { // Other roles, do something different }


2

I assume, you need something like editors can't see the category column or something like this. This snippet might help you: /** Remove "Options"-Panel, when User is not admin **/ add_filter( 'manage_posts_columns', 'change_columns_for_user', 10, 2 ); function change_columns_for_user( $columns, $post_type ){ if( 'post' != $post_type ) return ...


2

You can just grab the first post from the main query and see which post type it is: if ( have_posts() ) { $post_type = $wp_query->posts[0]->post_type; } If you run this code directly in a main template file you should be fine, but if it's in a function you will need to call global $wp_query; first.


2

WordPres has a function that extract IPTC info from images, that function is wp_read_image_metadata. That function is only available on admin side and, according with the codex, it doesn't extract IPTC keywords. But you can use iptcparse from PHP at your own to extract IPTC keywords and set them as post tags. In your question, you said that you have already ...


2

You want the first parameter ($post_type) of register_post_type() – by default this is used for the "slug", so in your case it's: content-block The name and singular-name labels you refer to are just for display purposes – see get_post_type_object() for an example. So this should work (note I've not tested the rest of your advert code): if (! is_single() ...


2

I don't think you need so many transients set, one for each category. You can only use one, that is enough. Transients are quite expensive to set as it requires additional db queries, so you would want to cut down on the use. As always, I like to keep my templates simple, short and sweet, so I tend to write custom functions to move the bulk of the code ...


2

get_post_ancestors() returns all of the ancestors hierarchically. As you only want to display the 2nd level post title on 4th post page, you can do something like - global $post; $parents = get_post_ancestors( get_the_ID() ); if( count($parents) == 4 ){ // ancestor1 = 1st parent, ancestor2 = second. echo get_the_title($parents['1']); // index ...


1

Once a post is moved to the trash and deleted, it's gone from the database. The only way to recover it is from an earlier database backup. Do you have a backup? Does your webhost have a backup?


1

Normally, posts are published by the wp_insert_post() function. Essentially, the post_status is changed from draft to publish. Nothing more to it than that, really. There is also the wp_publish_post() function, which is really only used for scheduled posts. It does the basic job of transitioning a post from "future" to "publish", and also calls the same ...


1

I think this is more a general question than a specific one and I'll be treating it as such. Taxonomies in general are used to group posts together that shares the same characteristic. The post_tag and category taxonomies are the most widely and commonly used of the four build in taxonomies to achieve this. Also very popular are custom taxonomies which ...


1

you may use <?php the_post_thumbnail();?> to display the image where you wish. If you still have any problem then please share the code you are using


1

get_post() returns a post object. So you can try the following $post = get_post( 1571 ); setup_postdata( $post ); the_title(); the_content(); wp_reset_postdata();


1

I have accepted the @websupporter answer according to my question. However I would like add few codes to specific question I have faced earlier. I need to remove Yoast SEO plugin extra columns from the non admin users. In that specific case Yoast SEO provide the hook to disable the columns. So I used that as below. /** Remove SEO columns when User is not ...


1

If I enter this shortcode: [download url="http://example.com"]Download[/download] it works fine. But you have to enter the link text as content yourself. You might have missed that, the way I read your question. Your [demo]-Shortcode throughs an error. To see this, you need to have WP_DEBUG set to true: Notice: Undefined variable: func in ...


1

I'm not quite sure what you want to do as frankly, your terminology is a bit scrambled, and you example shortcode is also quite a mess. Before I start, you should start of by checking the following very important links Shortcode API WP_Query You should first start of by defining your attributes (and their defaults) which you need to use and pass to the ...


1

get_the_content() returns unfiltered content, and using a shortcode you cannot use the_content() to return filtered content as you cannot echo inside a shortcode. Your best option here will be is to applying the_content filters to get_the_content(), something like: apply_filters( 'the_content', get_the_content() ); EDIT Exact usage, replace $output .= ...


1

You can use $_GET to get the query string values and then pass it in the $args to create a dynamic WP_Query $after = $_GET['after']; $before = $_GET['before']; and then in the $args if ($after && $before) { $args = array( 'date_query' => array( array( 'after' => $after, 'before' ...


1

The is_home() conditional tag applies to the posts page according to your reading settings or home.php file as opposed to the is_front_page() conditional which applies to the page on front according to your reading settings or your front-page.php file, if it exists. Try changing is_home() to is_front_page() As for another possible problem might be, take a ...


1

In your functions.php file, use pre_get_posts and swap out the -1 in the following code with the category I.D you want to exclude from your posts page. function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '-1' ); } } add_action( 'pre_get_posts', 'exclude_category' ); ...


1

Before you get to relating things in WordPress, you should decide what things are. In a very nutshell there are: Posts of post types (native ones being pages and blog posts) Terms of taxonomies (native ones being tags and categories) There are some things that WordPress does smoothly out of the box. Such as post being assigned a term or term having a ...


1

Which wp_get_recent_posts()do you retrieve the most recent posts. For meta data, like published date and modified date use additional functions. For the published date is the_date() helpful. For the modified date use the_modified_date(). The functions are a part of the Template Tags, useful for Theme and direct output. But she have also parameters to get ...



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