Hot answers tagged

5

Say if your have header-video.php used for video post format. Replace get_header(); with get_header(get_post_format()); in your regular singular.php or index.php. If WP can find header-video.php it will load it otherwise it will automatically will fallback to header.php.


4

For the permanent solution, your SQL query is slightly off - you need: UPDATE db1357924680.wp_posts SET post_content = REPLACE( post_content, '[print_me]', '' ) WHERE post_content LIKE '%[print_me]%' MySQL replace example


3

Basically, when you want get posts, you should think about WP_Query. It's already in the docs for your question. You can get posts by an author like this $query = new WP_Query( array( 'author' => AUTHOR_ID, 'posts_per_page' => 5 ) ); You can even get posts by more than one author, like this $query = new WP_Query( array( 'author__in' ...


3

Register a collection post type to represent a single collection. You'll get permalinks and rewrite rules to resolve the requests for free. Insert a new collection post for a user when they create a collection, and save the chosen post IDs as an array in post meta. You can pass that array directly as post__in argument in a WP_Query instance to load the ...


2

No, that isn't normal for 23 posts. Note that "posts" is pretty wide concept in modern WordPress. Many things are posts without being obvious as such, for example parts of navigation menus. While 60k entries does sound excessive for a small site, there is no telling without examining actual data to determine which post types it belongs to and if those ...


2

The WP_Posts_List_Table class extends WP_List_Table and within the WP_List_Table::views() method we have the following dynamic views filter: /** * Filter the list of available list table views. * * The dynamic portion of the hook name, `$this->screen->id`, refers * to the ID of the current screen, usually a string. * * @since 3.5.0 * * @param ...


2

I think the problem may be that the_post_thumbnail() doesn't accept an ID as a parameter. Instead you should use get_the_post_thumbnail() which does accept an ID as a parameter: <?php echo get_the_post_thumbnail($authors_post->ID); ?>


2

Go to Settings > Permalinks and set your permalink structure to /%postname%.php. Simples.


2

That looks like that's the Recent Comments widget in your sidebar. If so, go to Appearance -> Widgets in your site's admin and either delete the Recent Comments widget or drag it to the Inactive Widgets area.


2

You can use output buffering to achieve this effect: function get_comments_form() { ob_start(); comments_form(); $commentsform = ob_get_contents(); ob_end_clean(); return $commentsform; } $commentsform = get_comments_form();


2

There is an easier way to do this: add_filter( 'the_content', 'my_post_content_remove_shortcodes', 0 ); function my_post_content_remove_shortcodes( $content ) { /* Create an array of all the shortcode tags. */ $shortcode_tags = array( 'shortcode_1', 'shortcode_2', 'shortcode_3' ); /* Loop through the shortcodes and ...


2

Fiddling with user roles would probably be the most robust solution, however a quick and dirty approach would be to set post meta-data to mark posts that should be hidden, then add a meta-query to post queries by using a pre_get_posts hook in order to restrict results to non-hidden posts for non-logged-in users. The following will limit all posts queried ...


2

I am not familiar with the plugin, but it seems unlikely that the $conditions array you're adding to should contain any variety of WordPress query arguments. Further, referencing the $conditions array within a property that you're setting on that very array won't contain the new data you've added, but rather the array as it existed before your additions ...


2

"You should not write to the DB on front end requests" is the eleventh commandment. Your performance will deteriorate due to the writes locking down the table much more than the impact the size of the table will have. You should probably write such data in files instead of DB, or at least use a different table.


1

Sticky posts are a pain in the butt, and is not properly implememnted IMHO. The source code clearly shows that sticky posts are only moved to the top on page one of the homepage (or any custom instance of WP_Query which emulates the homepage), sticky posts does not get removed from the paged pages. This, IMO, should be part of core, stickies should be moved ...


1

Not a print to Wordpress plugin as such, but this will import the PDF text into the editor. https://wordpress.org/plugins/aspose-pdf-importer/ Or use a custom PHP class such as: http://www.phpclasses.org/package/9423-PHP-Convert-PDF-to-HTML-using-Poppler.html which will convert the pdf to html, hopefully with styles. You'd need to create a page template ...


1

Yes, you can use Admin Columns Pro (paid plugin with free version) to use inline edit for custom fields columns just from the WordPress posts list. It even comes with sorting and filtering for columns. You can easily add new columns with this plugin. https://www.admincolumns.com/ There are also plugins that allows you to bulk edit custom fields from the ...


1

I figured this out. Even though Wordpress automatically adds the <p> tag and doesn't show it to you in the editor (in either the 'visual' or 'text' editor views), you can type it in anyway in the 'text' editor view, along with a class. So to do this, go to the 'text' editor view, and just type, e.g., <p class="section-break>Here is the first ...


1

This is that classic question, do you have 6 eggs or half a dozen, and frankly, it doesn't actually matter. It is however better to use get_comments_number() because the post object is retrieved from the $GLOBALS['post'] global which is set by the_post() inside the loop the post object is validated through WP_Post (through get_post()) the output from ...


1

If you want sequential numbers for your posts, then don't use the post ID column. AUTO_INCREMENT is meant to provide unique numbers (and split-brains in multi-master replication), it is never going to be without gaps, especially not in WordPress (revisions, autosaves, pages, contact forms, galleries and a bunch of other plugins) and especially not with ...


1

Your best bet is not to run a bunch of queries but to loop through your data once to organize it then a second time to display it. Below is the logic you need. The exact code will depend on your data set. $events = array(); $posts = WP_Query( $args ); foreach ( $posts as $post ) { $venue = $post->venue; $day_of_month = date( 'd', $post->date ); ...


1

WordPress creates the default query on each page automatically based on the requested URL. Your template file should contain the standard loop to output whatever the default query contains. if( have_posts() ){ while( have_posts() ){ the_post(); the_title(); the_content(); } }


1

Your code has many errors:- $thumbs isn't used anywhere. $img_url = $thumb['url']; undefined variable if(is_array($thumb) && $img_url) always false because of second point. $search_data = []; should be outside of loop. Check the correct part of code $search_data = []; if($query->have_posts()): while($query->have_posts()): ...


1

ok, in a straight WP theme file (single.php) i simply found the_content(); and placed this after it since i wasn't worried about the placement of the link too much: edit_post_link( $link, $before, $after, get_the_ID() ); worked great.


1

Based on your comment clarifying what you want to achieve, it appears you want to display the first 60 characters of your post not including any shortcodes. To do this you can use the strip_shortcodes() function. Rewritten with that, your code will look like this: $content = strip_shortcodes(get_the_content()); $content = apply_filters('the_content', ...


1

You need to prepend value stored in _subtitle to the content of the post so that it works. Please place following code in your theme's functions.php file and it shall work. Please let me know how it goes so that I may assist further: add_filter( 'the_content', 'prepend_subtitle_to_content' ); function prepend_subtitle_to_content( $content ){ $subtitle = ...


1

Those statuses are turned from get_available_post_statuses(), which in turn gets its values from wp_count_posts(). wp_count_posts() passes it's values through the wp_count_posts filter. So you can tap into that and hijack what gets returned. Try this: function _dbdb_wp_count_posts( $counts, $type, $perm ) { global $pagenow; if( 'edit.php' !== ...



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