New answers tagged

0

i got the same problems several times ago, and it's caused by file permission in linux. for make sure about the problems, would you like to show us about the errors by adding below code in your wp-config.php define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', true ); be better if you give web console message to when you ...


0

WordPress uses something called Post Types to generate different types of content. The first URL belongs to a post ( default type ). You can access it under the "Posts" menu. The seconds URL belongs to a post type called "page", or simply a Page. You can access it under the "Pages" menu. To achieve what you need, you can make a ...


0

bunu kullan $author_posts = new WP_Query( array( 'cat' => '1,3', 'post_type' => 'any', 'post_status' => 'publish', 'author' => $user_id, 'fields' => 'ids', 'monthnum' => date( 'm' ), // Whatever the current month is ) );


1

IF HOT NEWS IS A TAG (FIRST QUESTION ASKED FOR TAGS) You gotta use a WP query where you query posts which have the tag "hot news" and order the result in descending order of the post ID, and then return 1 post, sth like this: $query_args = array( 'post_type' => 'your_post_type', 'tax_query' => array( array( 'taxonomy' => '...


0

If you look at the documentation for the media endpoint, you'll see there's a field, post, that you can use to attach media to a post using its ID. post The ID for the associated post of the attachment.


0

add_filter('wp_title', 'filter_pagetitle'); function filter_pagetitle($title) { if ( is_single() && 'post' == get_post_type() ) { return $title ."<br>THIS ARTICLE MAY CONTAIN COMPENSATED LINKS. PLEASE READ DISCLAIMER FOR MORE INFO"; } return $title; } Add this to function.php it will be add specified text on the ...


0

Something like this in your template files <h1><?php the_title(); ?></h1> <p><small>THIS ARTICLE MAY CONTAIN COMPENSATED LINKS. PLEASE READ <a href="/link-to-disclaimber/">DISCLAIMER</a> FOR MORE INFO.</small></p>


0

Googling for the Exception message There is no suitable CSPRNG installed on your system Yielded a Stackoverflow question matching your issue. When dealing with error messages, especially from plugins, it's usually helpful to Google the message itself - odds are someone else has already had the same problem, or the plugin maintainer may have addressed it in ...


0

Here is the correct code. It shows authors post count from a specific category by category slug name. $user_id = get_the_author_meta('ID'); $args = array( 'author' => $user_id, 'category_name' => 'category_slug_name', ); $my_query = new WP_Query( $args ); $my_count = $my_query->post_count; echo $my_count;


1

Easy and straightforward approach. $word_count = str_word_count(trim(strip_tags($post->post_content)));


0

WordPress already has current-menu-item class. Following CSS can be applied. .current-menu-item{ background-color:#4ba668; color: white; display:block; } Thanks to bosco for his comment.


0

Nevermind, I've managed to solve it. For anyone interested, the problem was 'category__in' isn't support by custom post types so instead needed to edit the $args array to include 'tax_query'. $args = array( 'post_type' => 'libraries', 'tax_query' => array( array( 'taxonomy' => 'library_types', ...


0

Well in the end I used custom taxonomy, and it's also more simple to manage. I post as I did : //hook into the init action and call create_topics_nonhierarchical_taxonomy when it fires add_action( 'init', 'create_regions_nonhierarchical_taxonomy', 0 ); function create_regions_nonhierarchical_taxonomy() { // Labels part for the GUI $labels = array( ...


0

You don't need to loop through the posts for this. Instead, just call the method get_posts() which will return an array of posts and then just count the number of posts in that array. $user_id = get_the_author_meta('ID'); $args = array( 'author_name' => $user_id, 'category_name' => 'categoryname', ); $wp_query = new WP_Query($...


0

The fatal error occurs because there are multiple functions with the same name. Function names must be unique. Remove the duplicate functions or rename the functions so that they are all unique and the fatal error should go away.


1

You may use a code like this: if ($the_query->have_posts()) { $first_post = $the_query->posts[0]; echo "1st post title\t:"$first_post->post_title; }


0

By default, the query will display by parameter from the user role (capacity) If your role dont have capacity to display the preview mode, you will need to add it in query. The function below will allow only the author (without capacity to preview mode) /** * ALlow the preview pending for post author * * @since 1.0.0 */ function ...


0

Below SQL query replaces the malicious script with a blank: UPDATE wp_posts SET post_content = REPLACE(post_content, '<script src=\'https://https://xyz/js.php?s=q\' type=\'text/javascript\'>', ' ')


1

If you use that filter in custom plugin, you will need to use the function "get_post_meta" because the function "get_page_templ‌​ate_slug" is not already loaded exemple: add_filter('display_post_states', 'wpse240081_custom_post_states', 10, 2); function wpse240081_custom_post_states( $states, $post ) { // if is list page and ...


1

here we go, this is the code that works, triggering an email-alert when a specific article is viewed function email_alert() { global $post; if( $post->ID == 1234) { wp_mail( 'aprilia@example.net', 'Alert', 'This Site was Visited!' ); } } add_action( 'wp', 'email_alert' );


0

according to this article, I think a specific post could be adressed like this function email_alert() { global $post; if( $post->ID == 1234) { wp_mail( 'aprilia@example.net', 'Alert', 'This Site was Visited!' ); } add_action( 'wp', 'email_alert' ); } however, emails are still not being sent for some reasons. happy for all inputs and ...


1

There's no is_article. I assume you guessed there would be analogously to is_page, but I don't think article is a built-in WordPress post type. I think you want is_page instead, which looks like it covers all post types. You should also move the page check into the action handler, to be sure that WordPress has enough state loaded to know if it's on that page ...


0

You could develop a plugin to track which URLs are getting requested, store that as a custom field for each post, and then run a cron job to delete the post_id that have post_views == 0 after a set period of time.


0

On the post edit screens when Gutenberg is enabled, you may use a JS variable set by the wp.media object. wp.media.view.settings.post.id, On the front end, the best approach was already outlined above.


0

OK I finaly decided to create a PHP Class for that specific post type and call as many instances as needed. I'm pretty sure that's the best approach, still listenning to all incoming advices


0

I think this is the solution that you need: <input onclick="window.location.href = '/#functioncode';" type="submit" value="Submit request" /> Found in a different stack. Normally I use this to redirect to a 'Thank You' page to track conversions, but it should work equally well with your anchor. Here's what it looks like ...


0

I'd strongly advise you to break out the js code rather than having it in HTML attributes, it's just so much more readable. However, as you've written it, this should fix your problem: <form method="post" onsubmit="event.preventDefault();functionCookie(this);"> The default action for a form, when it's submitted (the "event&...


0

Another Solution: function wp_redirect_post_location( $location ) { if ( 'post' == get_post_type() ) { if ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) ) return admin_url( "edit.php?post_type=post" ); } return $location; } add_filter( 'redirect_post_location', 'wp_redirect_post_location' );


1

Your first screenshot is the block editor. The new editor introduced in WordPress 5.0. It is the default editor, so yes, it is what you "should" get when creating a post. The second screenshot shows the classic editor, which is often still used for custom post types. If you want to use this editor for Posts (and Pages) you will need to install the ...


0

Yes. https://developer.wordpress.org/reference/hooks/before_delete_post/ It’s important to note the hook runs only when the WordPress user empties the Trash. If you’re using this hook note that it will not fire if the user is deleting an Attachment, since attachments are force deleted, i.e., not sent to the Trash. Instead use the delete_post() hook.


2

Not exactly sure what you are trying to do and this doesn't look like a WordPress issue, but submitting a html form will certainly lead to a new page load. So what you want is redirect not to the same page (which happens when you specify no action, leading the page to scroll to the top) but to an anchor on that page. The usual way to do this is to include it ...


1

You probably can't find any attached images because those images are not considered 'attached' or have been attached to another post before. With this script you can search directly in the_content() for all the attached images and then create another list with only the <img> tags cleaned from the rest of the text. $post_content = $post->post_content;...


0

You can filter the output like bellow: <?php /** * @param $revision_date_author * @param $revision * @param $link * @return mixed */ function filter_wp_post_revision_title_expanded( $revision_date_author, $revision, $link ) { $revision = get_post( $revision ); if ( ! $revision ) { return $revision; } if ( ! in_array( $...


1

In the page editor, switch to code-editor. Now your text will be within tags... probably a <p> tag. Add css to the tag so it reads: <p style="border: 1px solid gray"> ... </p> Currently, to switch to code-editor, click the 3-dot-menu-button in the right top of the screen/window and then "Code Editor".


3

WordPress 5.7 introduces a new helper function to more easily fetch the parent post's ID: get_parent_post() This can also be used in conjunction with has_parent_post(), so you could have something like looks like: <?php if ( has_parent_post() ) : ?> <a href="<?php the_permalink( get_parent_post() ); ?>"> <?php ...


0

You need to target the the_title filter. In that filter we can manipulate the output string as we need. add_filter('the_title', 'bt_the_title'); function bt_the_title ($title) { if (current_user_can('administrator')) { if (strlen($title) > 15) { $title = '<span class="font18px">' . $title . '</span>'; ...


2

You have to follow this file name structure: single-{post-type}-{slug}.php If you have a post names "Hello World" and the slug of post is hello-world then the template name will be single-post-hello-world.php Update: There is no default way to use id in template name. But you might try this snipped: <?php add_filter( 'single_template', '...


1

Wrap the div with a if condition like this. It should do the job! <?php if($qo->description):?> <div class="row"> <div class="col-sm-8 mx-auto py-5"> <?php echo nl2br($qo->description) ?> </div> </div> <?php endif; ?>


1

I would like to give an example to @Mark Kaplun's answer. You can register an endpoint to process your http post requests using register_rest_route like this:- /** first create a function for processing your request*/ function process_my_request(WP_REST_Request $request){ $request_body = $request->get_body_params(); if(update_post_meta( $...


0

That's strange, but nonetheless, you should know that whether you use cURL, PHP, JS, etc., if you're sending a JSON data, then you should set the Content-Type header to application/json. And via the cURL command line, you can use the -H option: curl --user "username:password" -X POST \ -H "Content-Type: application/json" \ -i https://...


0

I wrote an update for this. I uses the build in WP Core schema to ensure all WP Core tables are there (even in the future when 6.0 or higher is released ). It removes corrupt rows and re-adds keys an primary keys. The script (and more explanation) can be seen over here: https://wpindexfixer.tools.managedwphosting.nl/ No need to guess the auto-increment value ...


Top 50 recent answers are included