New answers tagged

0

Currently, you have your variable defined below the include which would be too late. If you defined the variable above the include it should be accessible by whatever file is included. $hssHeading = "A new different Title"; include( locate_template( 'cp/heroSectionSmall.php', false, false ) ); <!-- heroSectionSmall.php --> echo $hssHeading; Maybe a ...


1

there is a custom function in wordpress called date_i18n. so basically you do echo date_i18n( 'H:i d-m-Y', $ts ); without the setLocale stuff.. find the function date_i18n and its parameters here. you could even build in your translation all in there, without the language check before: date_i18n( __( 'H:i d-m-Y', 'textdomain' ) ); (replace 'textdomain' ...


0

You can do what you need to with the wp_list_pages() function: <?php wp_list_pages( [ 'child_of' => 92, 'title_li' => false, 'sort_column' => 'menu_order', ] ); ?>


0

Since you're using get_posts() rather than WP_Query, it's sufficient to retrieve the specific post separately with get_post(), and then add it to the beginning of the results array with array_unshift(): $postslist = get_posts( $args ); $featured_post = get_post( 123 ); array_unshift( $postslist, $featured_post ); foreach ( $postslist as $post ) : ...


0

The issue is that an empty return value from map_meta_cap will grant all users permission to do that thing, because that's essentially the same thing as saying "no capabilities are required to do this". What you really want to do is just add edit_special_page to the existing list of required capabilities: add_filter( 'map_meta_cap', function( $caps, $cap, $...


0

Rather than placing the result of wp_get_post_terms() into $episodes[$i], you can just merge it into the $episodes array using array_merge(), like this: $episodes = []; // Initialise as an empty array first. while( $animes->have_posts() ) { $animes->the_post(); $animeID[] = get_the_ID(); $args = array( 'orderby' => '...


1

The is_page_template() function is for checking if the current page is using a specific custom page template. That being a template selected from the Template dropdown in the Page Attributes box when editing the page. The WordPress conditional tags are not based around which template files are used. They are used to tell you what content is being viewed, ...


0

If I understand you correctly, your dummy_data.json file is placed in the root directory of your page (the same directory where index.php and wp-config.php are placed), right? In that case you can easily access that file passing this path: 'dummy_data.json' only when your code is run from index.php file. But AJAX calls are fun from wp-admin/admin-ajax.php ...


0

You could use AJAX if you don't want to reload the current page — i.e. upon clicking the "Accept" button, make an AJAX request to update the user metadata, all without leaving the current page. However, the solution I'm proposing is not using AJAX; instead, we simply submit the form (set its action attribute value) to the homepage and then we use the ...


0

You will need to use wp_localize_script() also available here. Short story : it's the WordPress way to call PHP in JS So you could do something like the following. FIRST create a js folder at the root of your theme, same level as style.css, if you do not have one yet, then in this js folder create a file call-php.js. You can name it what ever you want, the ...


1

Apparently Woocommerce need a local path and not a URL to the file. In order to fix I used this: function attach_order_notice ( $attachments, $email_id, $order ) { // Only for "New Order" email notification (for admin) //if( $email_id == 'new_order' ){ $file_path = wp_upload_dir()['path']; $file_name = get_field( '...


0

Within the parent container of the section whose left margin has to be removed add a class= "row ", and then in the child div element class = "col - * - 12"; , and then put * as md or sm or anything as required.


0

I finally found the problem, in fact when you add pagination to visual composer post-grid shortcode, it will use ajax to load the things. But to communicate to the ajax php script it uses the post id. The problem is that the shortcode will have no post id if you create it live, or another post id if you use an external post as a model. Then to make it ...


0

This was due to having an inline <?php $post = get_post()?> After moving this out and making it global, images stopped duplicating.


1

My question is, should I be doing it this way? Yes, but only if the other possible/better fixes do not work for you. You can also read this article about troubleshooting common WordPress errors such as the "headers already sent" error. And when developing a plugin/theme, I suggest you to turn on WordPress debugging because normally, you would be able to ...


0

You can create AMP version of your page for mobile devices. Please check this tutorial: https://amp.dev/documentation/guides-and-tutorials/start/create/basic_markup?format=websites


-1

use shortcode inside single quotes as: do_shortcode('[my_short_code]');


0

get_post_meta( $appointment_id, '_appointment_guest_name', TRUE ); please make sure that $appointment_id will be the post id and meta_key name should be proper with that id you can check this in wp_postmeta table(check meta_key name is _appointment_guest_name or appointment_guest_name)


0

You can use WP_Query for that : $contentTypes = explode(',', $_POST['contents']); $qry = new WP_Query( array( 'post_type' => $contentTypes )); if( $qry->have_posts() ){ while( $qry->have_posts() ) { $qry->the_post() // Your code } } Here is the [docs] ( https://codex.wordpress.org/Class_Reference/WP_Query ) for WP_Query


0

From what I can tell opinion is divided on how to handle this (although Tom Macfarlin - a reputable and well respected WordPress contributor more or less suggests to do what I've used to solve this. For good measure, I added ob_flush(); after ob_start(); as I couldn't sensibly see that I should start an output buffer and leave it in that state. A concern ...


0

I search to do that and finally found a solution.You can do something like that: This implies that your products have a repeater field "tabs" that contains a subfield "title" and a subfield "content". add_filter( 'woocommerce_product_tabs', 'prefix_other_products_tab' ); function prefix_other_products_tab( $tabs ) { global $product; $...


0

Use get_the_id rather than global $post; get_the_ID() Update Like this function add_to_system() { mail("michael.mcgurk87@yahoo.co.uk","My subject",get_the_ID()); } add_action('booked_new_appointment_created', 'add_to_system', 99);


1

Only posting an alternative answer despite the question being about a 3rd-party plugin, whose source code isn't even freely available, because I don't believe the accepted answer is likely to be a good solution. It's not documented on their website, but a comment from the developer states: These would all be considered custom requests, which our free ...


-1

try with this : function add_to_system($appointment_id) { mail("michael.mcgurk87@yahoo.co.uk","My subject",$appointment_id); } add_action('booked_new_appointment_created', 'add_to_system', 99,1); let me know if it works for you!


0

I found this article by Jeroen Sormani which solved my problem


0

Please try below snippet of code. HTML : <input name="getUser" id="getUser" value=''/> <div id="user_data"></div> JS (js/my-ajax-script.js) jQuery(document).ready(function($){ $('#getUser').keyup(function(e) { var user_id = e.target.value; console.log(user_id); $.ajax({ url:my_ajax_object.ajaxurl, #add ...


1

This line is responsible for posts that are showing: query_posts('showposts=4'); All you tell in it is “take 4 posts” and WP will take 4 most recent posts, because that’s the default behavior. If you want to take random posts, you have to tell WP to order posts randomly: query_posts( array( 'posts_per_page' => 4, 'orderby' => 'rand' ) );


0

I asked this on stack overflow as well. You can find that answer here: https://stackoverflow.com/a/56801044/343292 I'll copy and paste the answer below incase the link ever breaks. It worked for me. I used the dynamic way. ANSWER FROM @Sally CJ Note: I'm assuming WordPress is installed in the root folder. So if you want http://example.com/apple-app-site-...


0

I assume the shortcode you're using renders some html. If this is the case, then you could consider hooking your function to some later action, maybe one in your theme, so that the shortcode content gets rendered along with all the other html. You could even consider using wp_footer, if such late hook is ok. You could then maybe write your functions ...


0

I know this is solved for op but for other users that come along from Google this is what I had to do: Go to WordFence "all options" page Search "rest" in the filter Uncheck the option "Prevent discovery of usernames through '/?author=N' scans, the oEmbed API, and the WordPress REST API" Go to LiteSpeed Cache and choose Purge All You might be using ...


0

Well I got it working with a different approach but a good answer that provides insight why the approach in my question didn't work will be accepted as the answer. I put this in functions.php for the child theme: add_action( 'genesis_before_header', 'bob_gray_image', 10 ); function bob_gray_image() { if ( is_front_page() ) { echo('<div ...


0

Why do you have curly brackets in there? Maybe sanitize/process the query string with htmlspecialchars() first. The error is complaining about non-standard characters...which is what your curly brackets are doing. Build the query string with the $ip value, convert with htmlspecialchars(), then add the URL to the query string. Pass that variable to the ...


0

Maybe your .htaccess file is not writable if you are using debian or Linux based system aur Mac base system there are must be chances off the permission issue of the .htaccess file. First you need to check that that file is writable or not why WordPress? Because wordpress changes active .htaccess by own if you change any permalink settings wordpress ...


1

You should use WordPress functions to get the user role by user id. Please try code given below: function user_role_parameter($user_id) { $user_meta = get_userdata($user_id); if ( !empty($user_meta) ) { $user_roles = $user_meta->roles; $user_role = ''; foreach( $user_roles as $role ){ $user_role .= $role . ', '...


0

You can test if the $thumb has any contents and then apply a class to the featured image block that you can use to hide the container. <?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' ); ?> <div id="post" class="featured-image <?php echo empty($thumb) ? 'no-featured-image-class' : ''...


2

I'm afraid you're doing it a little bit wrong... Here are the problems: post_count field contains the number of posts being displayed and not the offset. wp_count_posts returns the number of posts globally, not in current query (so it will not be true for queries that have some filters). echo $post_count; . '-' . $post_count; is not correct PHP code. So ...


1

Please add below code in your footer.php file above included JavaScript files : <?php if ( is_active_sidebar( 'footer-1' ) ){ dynamic_sidebar( 'footer-1' ); } if ( is_active_sidebar( 'footer-2' ) ){ dynamic_sidebar( 'footer-2' ); } if ( is_active_sidebar( 'footer-3' ) ){ dynamic_sidebar( 'footer-3' ); } ?>


0

If i understand you correctly here you want to display some text under each of the category titles on your shop page. Instead of editing the template i would suggest using a hook. To do this you should move your code into functions.php. The complete code would look something like this: add_action('woocommerce_after_subcategory_title', '...


0

I know this is old but here is the possible solution: $q->set('orderby', 'product_new product_old product_almost_new'); $q->set('order', 'DESC'); So just try to pass parameters as a string in required order.


0

Your own solution works I guess (double $$) but usually you do it this way: $quantity['type'] = 1; ${'message' . $quantity['type']} = 'hello'; echo $message1; // hello


2

You have not added wp_ajax_nopriv so that is the reason for ajax failure for non-logged in users. public function register() { add_action( 'wp_ajax_tidplus' , array( $this, 'post' ) ); add_action( 'wp_ajax_nopriv_tidplus' , array( $this, 'post' ) ); } Please do this change and check.


0

You can use a multidimensional array to get this format. Please see the example given below: $terms = get_terms( array( 'taxonomy' => "issueCompanion", 'hide_empty' => false, 'fields'=>'all' ) ) $multi_arr = array(); foreach($terms as $term){ $year = get_field('published_year', $term->term_id); $...


0

You can try below snippet of code. i have develop shortcode you can take reference from it. function current_user_data_func( $atts ) { extract( shortcode_atts( array( 'metakey' => '', 'user_field' => '', ), $atts) ); ob_start(); if(is_user_logged_in()) { $current_user = wp_get_current_user(); $...


2

Keep in mind not everyone is running JavaScript, so you really need a server-side form processor like PHP rather than relying solely on jQuery. Best thing to do on a WordPress site is create a plugin that processes your form. You can include helper libraries like FPDF to not only generate the PDFs but that also have the option to save them to your server ...


0

I was seeing inconsistent behavior with query parameters until I registered the parameter with Wordpress, like this: function add_query_vars_filter( $vars ) { $vars[] = "cooked"; return $vars; } add_filter( 'query_vars', 'add_query_vars_filter' ); See more here: get_query_var in Codex


0

I managed to use what you did and other resources to come up with my own solution! The code is short and sweet: class Clickable_Dropdown_Walker extends Walker_Nav_Menu { function start_el( &$output, $item, $item_output, $depth = 0, $args = array() ) { if( in_array( 'menu-item-has-children', $item->classes ) ){ $output .= '<...


0

I did this in my theme, so you can look at the whole code here: https://wordpress.org/themes/twenty8teen I used the standard walker and added a filter for 'walker_nav_menu_start_el'. Of course, I also wanted it to work for the fallback Page menu, so I cloned the standard walker and added the call to apply_filters with a slightly different filter. /** * ...


0

To return something, you need to create a string variable like this : $output = '<div><span class="authorboxsinglename">'.$coauthor->display_name.' </span></div>'; $output .= ' <div><span class="authorboxsinglebio">'.$coauthor->description.'</span></div>'; return $output; The main things to know here : ...


0

There's two ways to do it. First, you could put any HTML into a string, and concatenate it with ., and .= to add a string to an existing value. This way you can build up a large string and return it at the end: function torque_hello_world_shortcode() { $html = ''; if ( function_exists( 'get_coauthors' ) ) { $coauthors = get_coauthors(); ...


0

I have checked this code on WordPress 5.2 define( 'WP_DEBUG', true ); and it is perfectly working. I think you should reinstall the WordPress.


Top 50 recent answers are included