Adding a text link under the post title in the lists of posts

You can enhance, change the strings to each post title in the table view of backend on post via hook: add_filter( ‘post_row_actions’, array( $this, ‘add_archive_link’ ), 10, 2 ); See the result in this screenshot: Below you find my method to add a link /** * Add link on archive * * @uses get_post_type_object, get_archive_post_link, … Read more

How to get the post’s parent ID?

WordPress 5.7 introduces a new helper function to more easily fetch the parent post’s ID: get_post_parent() This can also be used in conjunction with has_post_parent(), so you could have something like looks like: <?php if ( has_post_parent() ) : ?> <a href=”<?php the_permalink( get_post_parent() ); ?>”> <?php echo sprintf( esc_html__( ‘Back to parent page: %s’, … Read more

Displaying a widget only on long posts (over X characters)

Use the function t5_word_count() from this answer and extend the method widget() in your widget class: public function widget( $args, $instance ) { if ( ! is_singular() ) return; $content = get_the_content( ”, TRUE ); $words = t5_word_count( $content ); if ( 50 > $words ) return; // print you widget }

How use %like% in sql statement wordpress

$wpdb->prepare() doesn’t actually fully support sprintf() placeholders. From the Codex: The query parameter for prepare accepts sprintf()-like placeholders. The %s (string), %d (integer) and %f (float) formats are supported. It’s not entirely obvious from that but the argument swapping formats (e.g. %1$d) are not supported (in any case you have the incorrect syntax: it should … Read more

Custom Taxonomy – Tags Metabox is showing instead of Categories

You need to set hierarchical argument of your taxonomy to true (by default it’s false): function product_category_taxonomy() { $labels = array( ‘name’ => __( ‘Product Categories’ ), ‘singular_name’ => __( ‘Product Category’ ), ‘search_items’ => __( ‘Search Product Categories’ ), ‘all_items’ => __( ‘All Product Categories’ ), ‘parent_item’ => __( ‘Parent Product Category’ ), ‘parent_item_colon’ … Read more

Notification to Admin or Author upon new post [duplicate]

You need to write your hook for transition_post_status action: function authorNotification( $new_status, $old_status, $post ) { if ( $new_status == ‘publish’ && $old_status != ‘publish’ ) { $author = get_userdata($post->post_author); $message = ” Hi “.$author->display_name.”, New post, “.$post->post_title.” has just been published at “.get_permalink( $post->ID ).”. “; wp_mail($author->user_email, “New Post Published”, $message); } } add_action(‘transition_post_status’, … Read more

setup_postdata doesn`t seem ot be working

According to the Codex, you seem to skip the most important global $post; at the beginning, like this: global $post; $posts = get_posts($args); foreach($posts as $post) { setup_postdata($post); ?> <article class=”col two tablet-four mobile-six box”> <a href=”https://wordpress.stackexchange.com/questions/131909/<?php the_permalink(); ?>” title=”<?php the_title_attribute(); ?>”> <div class=”featured-image”> <?php if(has_post_thumbnail(get_the_ID())): ?> <?php $image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), array(650,200)); ?> <div style=”background: … Read more