New answers tagged

0

You might want to load all the items on the page at the same time, and use jQuery to display however many at a time. So for example: By default you could load (to the DOM) and hide all of them, then load 4 at a time using jQuery's slice Here's an example for my videos, however you could also hide the previous 4 videos before loading the next 4 to simulate ...


0

Have a look at wp-cli and wp-api they could help you automate your process without you needing to know too much about wordpress.


0

Posts have a slug (that's the last part of the URL), and it must be distinct, even if posts are in different categories. If your only worry is SEO, don't worry. Google sees the URLs as distinct, and Google is used to dealing with URLs that have a suffix on them, and has no problems with it. The keywords in the URL are still the same and have the same ...


0

Try adding this to your functions.php - it will wrap the image in the div you want. function filter_image_send_to_editor($html, $id, $caption, $title, $align, $url, $size, $alt) { return '<div class="post-page-image" id="image-'.$id.'">'.$html.'</div>'; } add_filter('image_send_to_editor', 'filter_image_send_to_editor', 10, 8);


5

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

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 ...


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 ...


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 ...


0

http://wordpress.stackexchange.com/a/199997/86773 As the advice suggested here, switching my hook to "wp" instead of "init" allowed me to make the page comparison I wanted using is_page().


0

Have you tried get_the_ID function? Try this one to get the ID and after that you can get all the info you want. Does it help?


0

Florian's answer is probably your best bet because it gives the author the most control as to how the images are aligned so that would be my first answer. However, if you don't trust your authors to align the images themselves then we'll have to go another route. Unfortunately for the reasons you stated above, it doesn't look like we can use the :nth-child ...


0

I don't think Visual Composer is the problem. Have you installed a logging plugin? Open phpMyAdmin and simply delete them. They are likely a post type you dont use. You can use the following query DELETE FROM wp_posts WHERE wp_posts.post_type='suspected_posttype' Make sure you don't remove the posta that are used by your site. Check what post types you ...


0

Have the writer use the left/right align functionality built into the WordPress text editor. The editor adds alignleft or alignright classes to the aligned images. Way more info can be found in the WordPress codex.


0

You could do this with a simple script. IMPORTANT! - Backup your database before doing this & attempt at your own risk. Create a file called changeauthorcat.php in your main WordPress folder. <?php include( 'wp-config.php' ); global $wpdb; // Author username $username = 'exampleuser'; // New category slug $newCatSlug = 'examplecategory'; // find ...


0

You can get author posts id's ids =[] ids = SELECT id FROM `wp_posts` WHERE `post_author`=1 and then you can loop result new_category_id = 999 old_category_id = 111 for id in ids: UPDATE `wp_term_relationships` SET `term_taxonomy_id`=new_id WHERE `object_id`=id AND `term_taxonomy_id`=old_category_id or wp_set_post_categories( $post_ID, ...


0

Ok, I solved this with a nice function, now the only thing left to do is to find a way to update all of the blog posts. doing this by hand will be really bad here is the code that I used add_action( 'save_post', 'myplugin_save_postdata' ); function myplugin_save_postdata( $post_id ) { if ( 'page' == $_POST['post_type'] ) { if ( ! current_user_can( ...


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.


0

This is how I bootstrapped youtube embeds in one of my projects. /** * Responsive Youtube embeds. */ add_filter( 'embed_oembed_html', function( $html, $url, $attr, $post_ID ) { if ( false !== stripos( $html, '<iframe ' ) && false !== stripos( $html, '.youtube.com/embed' ) ) { $html = sprintf('<div class="embed-responsive ...


0

An way to do that is using SQL. You probably have access to the database, so you can run this daily. It's not automatic, but will solve your problem UPDATE wp_posts SET post_status='publish' WHERE post_status='draft' AND post_type='post' ORDER BY rand() LIMIT 5000 Just to explain what this line do: It will get 5000 items (LIMIT 5000) in a random order ...


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.


0

Assuming post type is my-post-type. We can create a page template with custom query using WP_Query. Let's say we create template-multier.php with the below code in the root directory of the active theme. <?php /* Template Name: Custom Post Type Archive */ //Custom header stuff here //Custom query for `my-post-type` $args = ...


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

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', ...


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 ...


-1

working code function list_post_data(){ $args="SELECT * FROM wp_posts WHERE wp_posts.`post_type` = 'post' AND wp_posts.`post_status` = 'publish'"; $args = array( 'post_type' => 'post' ); $loop = new WP_Query( $args ); $array = array(); while ( $loop->have_posts() ) : $loop->the_post(); global ...


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

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(); } }


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

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 ...


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' !== ...


0

I view get_the_excerpt() as a function with legacy design. As WordPress usage has grown there are many newer use-cases where it doesn't fit but where the newer functions for getting different data do. One example is the now frequent use of an $args array of function options. But it's easy to fix for your needs. Here's an alternative function you can use ...


0

Its because you where ahead of time!


-1

changed timezone from Asmterdam to UTC(+1) and now it does work


0

I played around with the plugin files and was able to figure it out myself. For anyone who's wondering, you can use wp_insert_post. You just need to find what variable the generated shortcode is stored in, which can take a little digging through the plugin files. For the plugin I was working with, it went something like this: $my_poll = array( ...


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

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

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


0

I think you might have to modify the plugin, fork it, if you like the rest of it's functionality. Then add functionality that when you "favourite" a post/image, instead of adding it to your favourites you get a list which collection you want to add it to. All of these collections could have their own url like www.mysite.com/user/collections/collection-name ...


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' ...


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.


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 ...


0

For any one struggling with this there is an answer here on SO. As I am going to use this in multiple places I used the function answer. Add to be functions.php: function current_paged( $var = '' ) { if( empty( $var ) ) { global $wp_query; if( !isset( $wp_query->max_num_pages ) ) return; $pages = $wp_query->max_num_pages; } else { ...


-1

Use below code please, this will work. <a href="<?php the_permalink(); ?>">read more..</a> or <?php the_content( __( 'more <span class="meta-nav">...</span>', 'themename' ) ); ?>


0

<figure> <?php echo get_the_post_thumbnail( null, $size, $attr ); ?> <figcaption>here goes your caption</figcaption> </figure> for the_post_thumbnail check : https://developer.wordpress.org/reference/functions/the_post_thumbnail/


0

Just in case someone got here looking for how to also add a Guest Description, here is my full implementation. If follows the same logic as the other answers, I just added a get_the_author_description filter and a function to overwrite the author Bio info (description). As the other solutions above, you pass it as a custom field (see image attached). ...


0

You mentioned: Is there a way, to do that from within a plugin or a themes functions.php? You may want to try the following code. Just place it inside your theme's functions.php file. Using it, you do NOT have to alter the wp-config.php file. define('WP_POST_REVISIONS', false); function disable_autosave() { wp_deregister_script('autosave'); } ...


0

That message is a general PHP error saying that you are trying to use a variable like a PHP object when it is not a PHP object. If you read the docs for get_previous_post() and get_next_post(), you can see that those functions return a post object or null/empty string if the previous/next post couldn't be determined. So, you need to check that you have an ...


0

Can you access your site via FTP or through your host control panels file manager? If you can, check to see if there is any code within wp-comments-post.php in the root of your site. If it is empty, paste this inside: <?php /** * Handles Comment Post to WordPress and prevents duplicate comment posting. * * @package WordPress */ if ( 'POST' != ...


0

This post on the WordPress forums should provide some assistance. It uses the paginate_links function to generate the output.


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 ...



Top 50 recent answers are included