How to create a dynamically created page on wordpress plugin?
How to create a dynamically created page on wordpress plugin?
How to create a dynamically created page on wordpress plugin?
There were a couple security issues and error checking that I did see. Try these: <?php add_action(‘wp_ajax_get_timeslot_data’, ‘get_timeslot_data’); add_action(‘wp_ajax_nopriv_get_timeslot_data’, ‘get_timeslot_data’); function get_timeslot_data() { if (!isset($_POST[‘activityId’]) || !ctype_digit($_POST[‘activityId’])) { wp_send_json_error(“Invalid activity ID”); } global $wpdb; $activity_id = intval($_POST[‘activityId’]); $table_name = $wpdb->prefix . ‘booking_seasons’; // Support custom table prefixes $result = $wpdb->get_row($wpdb->prepare(“SELECT timeslot_dates FROM $table_name WHERE id … Read more
You can use the body_class filter and the wp_get_current_user() function to add the current user’s role to the <body> element, and then hide your elements with that (untested): add_filter( ‘body_class’, static function ( $classes ) { $user = wp_get_current_user(); $roles = $user->roles; if ( ! is_array( $roles ) ) { $roles = array( ‘subscriber’ ); … Read more
How to make search by ID work on front-end?
The error was occurring when someone hits a page that doesn’t exist (404). I created a custom 404 error page and the errors are now gone.
The get_the_ID() function uses the global $post variable, which outside of the loop is sometimes equal to get_queried_object_id(). Within the loop, the $post variable is set to the current post within the loop. As to why get_queried_object_id() is recommended outside of the loop, is because it does not use the global $post variable, so is … Read more
The ID field in the wp_post table should be an UNSIGNED BIGINT in MySQL. That means it can store values from 0 to 18,446,744,073,709,551,615 ((2^64)-1). See the MySQL documentation article for that. Your value of 796,978,707,878,960,002 is a not bigger than the allowed maximum value. So in theory it should be able to handle that … Read more
If I am understanding right, you’re suggesting creating separate database tables both for your post type and taxonomies. You don’t really need to do that at all. Just create a custom post type which WordPress will store in the {prefix}_posts table, and create a custom taxonomy for that post type which WordPress will also handle … Read more
Getting the correct post ID in WordPress query loop
Try this. Here is the full code that you can add to your functions.php file: // Add custom rewrite rules function add_custom_rewrite_rules() { add_rewrite_rule( ‘^category/([0-9]+)/?$’, ‘index.php?term_id=$matches[1]’, ‘top’ ); flush_rewrite_rules(false); // Temporarily set this to true to flush rules, then set back to false } add_action(‘init’, ‘add_custom_rewrite_rules’); // Add term_id to query vars function add_query_vars($vars) { … Read more