How to string lines from the_content() hook in WordPress?

I don’t know any other way There is a much, much better way to do this – custom fields. As per these instructions in the custom fields docs, let’s say you use the field name iframe_url: <iframe src=”https://wordpress.stackexchange.com/questions/230707/<?php echo esc_url( get_post_meta( $post->ID,”iframe_url’, true ) ?>” width=”960″ height=”540″ frameborder=”0″ allowfullscreen=”allowfullscreen”></iframe> <?php the_content() ?> See how much … Read more

Render a loop in Timber (twig for WordPress)

@Xroad, here’s the simplest way. Things can get a bit more complicated depending on the specifics, but this is the most straightforward way: $query = get_posts(array(‘post_type’ => ‘lexique’,’posts_per_page’ => -1)); $by_letter = array(); while( $query->have_posts() ) { $query->the_post(); global $post; $letter = substr($post->post_name, 0, 1); if ( ! isset($by_letter[$letter]) ) $by_letter[$letter] = array(); $by_letter[$letter][] = … Read more

show only one category posts in admin

to show one specific category posts in admin all posts page (edit.php?post_type=post) you need to join term_relationships table by filtering posts_join and adding where clause by filtering posts_where. eg. add_filter( ‘posts_join’, ‘hide_attachments_wpquery_join’ ); function hide_attachments_wpquery_join( $join, \WP_Query $query ) { global $wpdb; if( is_admin() && $query->query[‘post_type’] == “post” ) { $join .= ” LEFT JOIN … Read more

How to manage wordpress knowledge base/wiki/posts collections

WordPress already provides a built-in mechanism for navigating collections of posts called “Archives”. Taxonomies such as “Category” naturally create a collection of posts – and thus WordPress automatically facilitates taxonomy archives. Meanwhile, pages are intended to display singular, definitive content that is usually timeless. It sounds to me as though your “Topics” should be top-level … Read more

Display posts from another page on home page in wp-editor

I created shortcode in functions.php: add_shortcode(‘projects’, ‘projects_shortcode’); function projects_shortcode($atts){ extract(shortcode_atts(array( ‘post_type’ => ‘project’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => 3, //’caller_get_posts’ => 1 ), $atts)); $args = array( ‘post_type’ => $post_type, ‘post_status’ => $post_status, ‘posts_per_page’ => $posts_per_page ); global $post; $posts = new WP_Query($args); $out=””; if ($posts->have_posts()) while ($posts->have_posts()): $posts->the_post(); $overview_image = get_field(‘small_overview_image’); $out .= ‘<div … Read more

How to delete unnecessary custom post types in the UI

Currently there is no way on the backend (UI) for unregistering a post type, the process however is quite simple. Andrew Nacin provided some code over on https://core.trac.wordpress.org/ticket/14761 You can easily create a plugin with this function and have the CPT unregister. if ( ! function_exists( ‘unregister_post_type’ ) ) : function unregister_post_type( $post_type ) { … Read more