Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

1

Had the same problems here and there seems to be no movement on wordpress site. In my particular situation where for single blogposts the structure /blog/%postname%/ was needed this solution https://kellenmace.com/remove-custom-post-type-slug-from-permalinks/ ended in a bunch of 404s But together with this wonderful approach, which is not using the ...


0

It turns out the value that points to the PDFs' locations on disk is stored in the wp_postmeta table, under the meta_value field. For example a media item located at site.com/app/uploads/2019/06/whatever.pdf would have a meta_value value of 2019/06/whatever.pdf. To change the location of all PDFs I first found the IDs of all PDFs (from the ID column in the ...


0

You can do it in many ways but I think every needs to change your archive template (or other template which display your list). You can use some custom field plugins to add one with "Don't link do article" and set this in your template in places where you have anchors. That's a quick solution. But out-of-box Wordpress does not have any "link or not" solution....


-1

add this code in your search.php <?php $show_pagination = true; if($wp_query->post_count < 0) { $show_pagination = false; } ?> <?php if($show_pagination){ ?> <!-- The pagination component --> <div class="container"> <div class="row mt-3"> <?php ...


0

This issue may cause of some plugin Please do following - Check is there is any cron job set which creating post randomly - Check Is there is any form from front-end which creating post? - check deactivating all plugins one-by-one - Check by changing theme - check by updating/downgrading wordpress files


0

Figured it out. There is a revisions endpoint that you can query that will return the latest autosaved update. https://developer.wordpress.org/rest-api/reference/post-revisions/


1

What makes this annoying is that the count is a wp_term_taxonomy table. So the way to do this is a custom query: function wpse340250_term_count( WP_Term $term, $post_type) { $q_args = [ 'post_type' => $post_type, 'nopaging' => true, // no limit, pagination 'fields' => 'ids', // only return post id's instead of full ...


1

Hey I used this code for something similar(I was also downloading remote image and uploading to WordPress site). Please have a look: $image_url = $value;//This is the sanitized image url. $image = pathinfo($image_url);//Extracting information into array. $image_name = $image['basename']; $upload_dir = wp_upload_dir(); $image_data = file_get_contents($...


1

Building upon the accepted answer on the linked question, I think something like this might work. So basically, get the existing post content with get_post_field upload the image with wp_insert_attachment which gives you the image ID grab the image size and alt from the post content somehow let WP generate the markup for the image with ...


0

You want to use admin-post.php or admin-ajax.php (AJAX only) to allow your front-end form to interact with WordPress. Setting this up will allow you to create an action where you use the $_POST array to find the content you're looking for with WP_Query and print it out as the response to your request. Here's a decent guide to both methods: https://...


2

The block editor is restoring back the title that was last saved (or typed manually into the textarea), so with the block editor, you can change the title dynamically using this code: wp.data.dispatch( 'core/editor' ).editPost( { title: 'Title here' } ) PS: You should make sure your JS file has the wp-editor, wp-edit-post or wp-data as part of the ...


0

The only solution that worked for me happens to add an action filter to functions.php in the following format: add_action('pre_get_posts', function($q){ if (is_category()){ if(is_category('NEWS')): $q->set( 'posts_per_page', 2 ); endif; } });


0

look at http://www.mysqltutorial.org/mysql-find-duplicate-values/ to get meta values, you need to assign : wp_postmeta.meta_key = 'syndication_permalink' AND wp_postmeta.meta_value = '$yourvalue'


0

The easiest way is to tie into the WordPress action publish_post. Here is a link to the codex with a basic example: https://codex.wordpress.org/Plugin_API/Action_Reference/publish_post Note: If you are looking to do this for a Custom Post Type, you'll need to add an action for publish_custom_post_type.


0

You could add a GET parameter in your theme and then pick it up on the next page. Something like this, I guess. <a href="<?php the_permalink() ?>?source=<?php single_cat_title(); ?>"> Then you have (don't try this at home unsanitized data is bad for you): <?php if(isset($_GET['source'])){ ?> <p>You came from <?php echo $...


1

It can be done like this without having to rely on the $post global. if ( is_admin() ) { if( isset( $_GET['post'] ) && isset( $_GET['action'] ) && $_GET['action'] === 'edit' ) { $post_id = $_GET['post']; $current_post = get_post($post_id); $author_id = $current_post->post_author; } } The query string ...


0

Thanks to @bjornredemption, I used the following code snippet: $args = array('category' => $wp_query->get_queried_object_id(), 'posts_per_page' => -1, 'orderby'=> 'title', 'order' => 'ASC', 'post_type' => array( 'post', 'attachment'),'post_status' => array( 'publish', 'inherit')); $glossaryposts = get_posts( $args ); Furthermore the ...


1

Global attribute --url=<url> is required to post in a networked site. wp post create --url=subdomain.exampledomain.com [OPTIONS] Ref : https://developer.wordpress.org/cli/commands/post/create/


1

Something like this should work : $args = array ( 'post_type' => array( 'post', 'attachment'), 'category' => ARTICLE_CATID ); $query = new WP_Query( $args );


1

If you need to get tags by post id you could use the followng function. This will work on anywhere since the method is based on database querying. function sc_tf_get_tags_as_array($post_id){ global $wpdb; $tbl_terms = $wpdb->prefix . "terms"; $tbl_term_relationships = $wpdb->prefix . "term_relationships"; $sql = "...


0

Im really inexperienced with wordpress but i googled a few sec on google and maybe this will help. function is_user_logged_in() {     $user = wp_get_current_user();  //Try to detect if the user is in a group here     return $user->exists(); } Maybe you can try to do something with the page if the user is detected as user and in what group it is. ...


0

The $_SERVER['HTTP_REFERER'] isn't always that reliable as it depends on the HTTP Referer header being sent by the user's browser, so it may not always exist or could even be incorrect. MikeNGarret's solution of sending it in the url to the form would be a much more reliable way of doing it.


0

To get last-visited page URL $last_visited_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; to get post id, you can use url_to_postid( string $url ) this function. $last_visited_url_post_id = url_to_post_id( $last_visited_url )


0

I'd first make sure that everything is updated: WP, themes, plugins. Then I'd look at the plugin's WP page and see how long it's been since they have been updated. You might have some old plugins that could be causing problems, like maybe they are using old JS. I'd also look at the page source of a couple pages to see if there is anything unexpected (code)...


1

It would be best to include this in your link. For example, the link to your form could be https://domains.com/form/?product=20. That way the product ID will be available as as GET parameter, eg $_GET['product'].


0

I had the same problem of needing to only apply $post_clauses to specific loops/queries and was able to use THIS solution provided by Stephen Harris: You can access query variables (including custom ones) via the WP_Query::get() method. For example: $my_query = new WP_Query( array( ... 'wpse105219_custom_var' => 'foobar', ... )...


2

If you use WordPress author template to show user posts ( example.com/author/{user_name} ) the best solution will be to change the main query via the pre_get_posts filter hook. function se339534_author_any_post_types $query ) { // apply changes only for author archive page if ( ! is_author() || ! $query->is_main_query() ) return; $...


0

You might get away with shortcodes: add_shortcode('title', function ($atts, $content = null) { $atts = shortcode_atts([ 'id' => null, ], $atts); $title = ''; if (!empty($atts['id'])) { $title = get_the_title($atts['id']); } return $title; }); add_shortcode('content', function ($atts, $content = null) { $...


0

I'm not sure if this is what you mean but this Wordpress function can display list of authors: wp_list_authors( $args ); https://codex.wordpress.org/Function_Reference/wp_list_authors You can use this one to display the posts of an author: https://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters The author is the parameter.


0

Answer was simple: .single .efav-span {display: none} add spacing to each element


0

Here is a plugin that does the same. function get_posts_per_taxterm($taxonomy, $term_id ){ $posts = get_posts( array( 'posts_per_page' => -1, 'post_type' => 'post', 'orderby' => 'menu_order', 'order' => 'ASC', 'tax_query' => array( array( ...


0

I created a query, you can use this to find all the categories related to SELECT * FROM wpra_term_relationships INNER JOIN wpra_term_taxonomy ON (wpra_term_taxonomy.term_taxonomy_id=wpra_term_relationships.term_taxonomy_id AND wpra_term_taxonomy.taxonomy='category') INNER JOIN wpra_terms ON (wpra_terms.term_id=wpra_term_taxonomy.term_id ) WHERE object_id='...


0

There is probably some CSS you can add via Additional CSS (in Theme CUstomization) that you could use. Use the Inspector tool of your browser (F12) to see the CSS 'class' element used in the content. If the class is called 'the_content', then add this to your Additional CSS: .the_content{text-align:center !important;} You might need this, if the content is ...


1

Depending of what you are exactly trying to achieve accessing the first element of the $posts array may work for you. No need for the foreach loop. echo '<img src="'.$posts[0]['img']['url'].'">';


0

İ found a solution: $posts = get_queried_object(); echo $posts->count;


0

I found a solution!: $term_ids = $wpdb->get_col(" SELECT term_id FROM $wpdb->term_taxonomy INNER JOIN $wpdb->term_relationships ON $wpdb->term_taxonomy.term_taxonomy_id=$wpdb->term_relationships.term_taxonomy_id INNER JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->term_relationships.object_id WHERE DATE_SUB(CURDATE(), ...


2

You can see a practical example here: https://wordpress.stackexchange.com/a/142902/19105 Why do you need to use DISTINCT in this situation though? The WP_Query you provided shouldn't be giving duplicates unless there is a plugin causing trouble. But I'll try to answer it anyway. I would suggest keeping the function in functions.php. But move the filter to ...


0

The correct way is to use WordPress Cron and schedule your event. Also you should consider adding real cron job as outlined here for better precision. 1.) I modified your draft_the_post function to support parameter. So now we can specify which post and also i updated the portion that checking the time. 2.) dg_cron_schedule_delete_posts will schedule the ...


0

For the value 0 in add_post_meta the view count is not updating. Try the line add_post_meta($postID, $count_key, '1'); instead of line add_post_meta($postID, $count_key, '0');.


0

I was able to find some helpful articles, the combination of which helped me solve this. First, I discovered that the uploadedTo information can retrieved, returning the ID. A bunch of information on attachment data can be found here. Second, I was able to convert the ID into a link for the post by simply adding some html <a href="/?p='.$attachment_data['...


0

Can't give you fish, but I can try you to teach how to fish with a couple of pointers; hook into publish_post (good example code there) and / or post_updated in the function that is called that way, use wp_create_category (which will only create if the cat. name doesn't exist yet) and with the cat ID you get that you then call wp_set_post_categories (make ...


0

You may want to try a few PDF generation plugins out there. I did some quick Googling and found https://wordpress.org/plugins/wp-pdf-generator/ (but I would recommend searching for others). Once installed, you can directly link your users to the "generate pdf" link instead of the Custom Post Type permalink, generating the PDF automatically for them. You ...


0

First, really stupid question: Do you save your new menu after making the changes? Sometimes it's the little things that mess everything up. Aside from that, it might be a theme problem. Change to one of WordPress default themes (Twenty XYZ series) and see if the problem persists.


0

If you wish to get posts between two dates, then use the before and after parameters in the date_query parameter, $query_string = array( 'post_type' => 'post', 'date_query' => array( 'column' => 'post_date', 'after' => '2012-04-01', 'before' => '2012-04-30' ), 'tax_query' => array( array( 'taxonomy' =&...


0

yes, it is possible. add a template_redirect hook handler: add_filter('template_redirect', 'redirect_post_to_canonical_url'); function redirect_post_to_canonical_url(): void { if (!is_single()) { // do not redirect nothing else except posts return; } $canonicalLocation = get_permalink(); $requestUri = $_SERVER['REQUEST_URI']...


0

If your theme is called my-theme the configuration is stored as serialized PHP object in a option name called theme_mods_my-theme in the wp_options table in your Wordpress database. Use any Database editor tool to execute the query: SELECT * FROM `wp_options` WHERE `option_name` LIKE 'theme_mods_%' with will return all the customizations for every theme ...


1

Expanding on other answers here for use with only a specific post type. add_action( 'before_delete_post', 'delete_all_attached_media' ); function delete_all_attached_media( $post_id ) { if( get_post_type($post_id) == "post" ) { $attachments = get_attached_media( '', $post_id ); foreach ($attachments as $attachment) { wp_delete_attachment( ...


0

As the commenters have noticed wp_unique_post_slug is called from wp_insert_post to ensure there are no double slugs. It is also called from two other functions, which explains why it is a separate function and not incorporated in wp_insert_post. A little used feature is the possibility to apply filters present in wp_unique_post_slug. There are two of them: ...


Top 50 recent answers are included