New answers tagged

-1

Thanks guys, the problem was solved. I looked more in the FTP and found a little readme.txt. The file had the name of the theme which was modified and made into a child theme. I googled it, downloaded it and got the functions.php. I still got a few errors but I just removed the lines that were causing the errors and now the site is working! Thanks everyone!


0

Thanks for rewriting the question: It seems much clearer now. Sorry for the protracted comments earlier, but I wasnt on my laptop. I corrected a couple of typos in your code and pasted this into my functions.php: // include files via shortcode function include_file($atts) { extract(shortcode_atts(array('filepath' => NULL), $atts)); if ($...


0

You may need to unserialize the data to get the array and loop through it thus: $userid = 832; // or 1540 $votes = get_post_meta($postid,'voter'); $votes = maybe_unserialize($votes); if (is_array($votes)) { // votes is the array, key is numeric index, vote is subarray foreach ($votes as $key => $vote) { // subarray values are in another ...


1

Forget about connecting to your database while WordPress is ready and connected by default. Go after wpdb class for DB-specific tasks. First, call the global $wpdb variable which is the db class, and then use few methods to query your specific custom table. Not sure about the table structure? describe it first: global $wpdb; $table = $wpdb->prefix . "...


0

If no role is checked when you submit, the $_POST['cat'] will not be set. That will trigger the "invalid argument supplied for foreach" error. In the beginning of your if ( isset($_POST['saveme']) ) structure, I'd put: if ( !isset($_POST['cat']) ) { // code to update db value to 0 }


0

If your web host won't let you have access to cron jobs, you can try one of the free external cron job services (I used one of these but now forgot which one) https://www.google.com/search?q=web+cron+free ... if your script has a public URL. I added a hashed code to my script to make sure no one could just call the script directly w/o the key.


0

your variable $roles , either contains no value or is not an array, foreach only process an array/object.


0

You have this code: elseif (17 < $count && $count <= 27 && $paged === 1) : if ($count === 10) echo 'DIV/CONTENT BEFORE THE NEXT 10 POST GOES HERE'; The first conditional fails when 10 === $count and so the second conditional can never succeed. As your while loop executes (in a structure that WordPress calls The Loop, calling ...


0

You need to create separate tables for store sticky notes and save user sticky notes to that tables , in this way you can manage multiple sticky notes of user. i think this idea will help you.


0

If I've understood correctly, you just want older images upgraded to be like newer images? Back up your data first, but if I have understood then just remaking your image sets with a plugin like Regenerate Thumbnails should do the trick. Test this out on a development copy of your site though!


0

You need the $post_id passed in to the function you are calling from the hook. Try making your function declaration like this: function slider_data( $post_id )


2

Problem The Short Version The problem isn't how you're using those scripts or where you're placing them - it's how the authors of those scripts wrote them. The Long Version Your "superfish" script which controls the functionality of your navigation menu is throwing errors because $.browser is undefined. While $.browser was deprecated more than 3 years ...


2

This should add the drop class to all the li elements in the menu and also add your classes to the wrapping ul: function wpse_232637_add_menu_parent_class( $items ) { foreach ( $items as $item ) { $item->classes[] = 'drop'; } return $items; } add_filter( 'wp_nav_menu_objects', 'wp_232637_add_menu_parent_class' ); $args = ...


0

If I understand your question correctly, I believe this is what you're looking for: <div class="postthumbnail"> <?php $usercrop = get_field('usercrop'); if ($usercrop) { $image = wp_get_attachment_image_src(get_field('usercrop'), 'full'); ?> <img class="post-thumbnail img-responsive postpic" src="<?php echo $image[...


-1

You need to define other sizes with this function


0

it's file_put_contents which saves the data then it have to be in the hook and not in the body of the plugin : function export_posts_in_json () { $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => -1, ); $query = new WP_Query( $args ); ... $data = json_encode($posts)...


0

this not perfect way to write inline java script , write java script into document ready event jQuerydocument ).ready(function() { jQuery( ".wc-proceed-to-checkout" ).css("display", "none"); });


-2

<?php global $wpdb; $table="test_table"; $store_arr["name"]="test"; $store_arr["email"]="test@gmail.com"; $wpdb->insert( $table, $store_arr); ?>


0

Why don't you create a shortcode for this , it's much easier, standard and flexible.


0

Short answer: most probably there is. I would recommend you use a child theme to achieve this. You can then copy any of the parent theme's templates into your child theme and alter them as you like. In your case it's probably something like "single-portfolio.php" inside the templates folder of the theme. A good starting point for working with child themes ...


0

If the client have authenticated successfully. You just need fetch post data with POST method: $post = [ 'title' => 'Test post with OAuth2', 'content' => 'Look like WordPress does not like this.', 'status' => 'private' ]; $response = $client->fetch('http://sitename.com/wp-json/wp/v2/posts', $post, 'POST'); echo '<pre>'; var_dump($...


0

It's a bad use of Query you may look at this post In this case use a secondary query with your own instance of WP Query. query_posts() is not recommanded here cause it overrides the main query. <?php $args = array( 'post_type' => 'instrument', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, ); $my_query = ...


0

I actually solved this... here's what you need to do if anyone needs to do something similar: SO, you can't really query a site, but you can query pages on sites... so what I did was make a new page on the site where everything looked good, embed the shortcode, query that page and the content only on the other site. You NEED to have the site switch to that ...


0

is_wp_error() functions return the post_ID on success. The value 0 or WP_Error on failure. $post = array( 'post_author' => 1, 'post_title' => 'my title, 'post_content' => 'my content', 'post_category' => array(3), 'post_type' => 'post', ); $ins_post = wp_insert_post($post); if(is_wp_error($ins_post)){ echo 'error'; }else{ echo '...


1

That's not a good practice trying to connect the DB by your own methods while WP does it for you initially. The problem with this is that I have to declare these variables ($db_host, $db_user, $db_pass, $db_name) inside the plugin source code. All these properties are defined in wp-config.php file, located in the root area. If you were to get ...


1

Why not study about how $wpdb works. Visit https://codex.wordpress.org/Class_Reference/wpdb Here is a example of how to insert data to database using $wpdb <?php global $wpdb; $wpdb->insert( 'table_name_here', array( 'column1' => 'value1', 'column2' => 123 ), array( '%s', '%d' ) ...


1

A simple answer to your question is that you have the data type as JSON in your ajax request and you are passing a string in it. You need to pass a json object in the ajax request when you chose dataType equals to JSON. A JSON object is typically a key pair value inside curly braces. Here is a reference where you can see how ajax requests can be implemented ...


0

I think you may have a problem in the way you establish your data. If you read the WP Codex on AJAX, you will see the data in the examples is in key/value pairs. That is, the data should look something like this: var data = { 'action' : 'do_ajax', 'fn' : 'change_due_date', 'newDate' : newDate }; Also, note the Codex says that ...


1

TomC is right, but to build on that here's what I do. Mainly I use this with a global object which I serialise into the session to save and unserialise from the session to use. Here I've just used an array of your variables. This way you don't need to worry about saving into the session as you go and the session use is easily expanded for other data. My ...


1

You want to use the init hook to start the session such as: function start_session() { if(!session_id()) { session_start(); } } add_action('init', 'start_session', 1); function end_session() { session_destroy (); } add_action('wp_logout', 'end_session'); add_action('wp_login', 'end_session'); This would go in the functions.php file. ...


0

You can get current user ID easily using get_current_user_id(). $usersid = get_current_user_id(); $activity = $_POST['activity']; $reason = $_POST['reason']; $explanation = $_POST['explanation']; For your function f2user() you can change your code to this: $current_user = wp_get_current_user(); return $current_user->ID; According to ...


2

The true maximum is ultimately up to the host - they can impose whatever limits they wish. But even so, you can try with WP_MEMORY_LIMIT, which is the memory limit WordPress sets at runtime for any given request. WP_MAX_MEMORY_LIMIT is only applied in certain situations, either for administrators in the backend (users with the capability manage_options), or ...


2

The solution to restrict access to author's archives with .htaccess rule does pretty decent job. However, not everyone can edit or have access to .htaccess, especially on shared hosting accounts. The code below require PHP version 5.3+. Here is the solution which deals with the problem on WordPress level. Put this code in your theme's function.php file: &...


0

You say "However, I know this is not a good way to do this" in your self answer. One thing I could add answering your question and using your answer is, you can use SQL_CALC_FOUND_ROWS with $wpdb $result = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM `wp_table` WHERE 1 LIMIT 10;" ); $total_count = $wpdb->get_var( "SELECT FOUND_ROWS()...


0

There's some code missing from your question - the code where your slides are actually output. The foreach loop you've posted only sets the variables, and the actual output happens below the loop. So, all you're doing on the fourth slide is avoiding setting the variables... hence the slide is still output, but using the third slide's variables. Your if ...


0

Turns out all of my attempts were viable (Thanks ehsaan for also confirming). The issue was that I was trying to get data from a field that was empty at the time of the function. (I was creating a new/updated post that hadn't updated the field yet). Solution (delay the hook): // Time out the custom field to update AFTER the post has been created/updated ...


-1

Are all the if-statements that output html actually inside the checkbox if-statement? Can't really tell from the way you've posted the code. It looks like maybe on the last trip through the foreach loop, the values of the variables are being remembered from the previous trip and outputting them again??


0

As milo stated, I need to use the post_class function to use the post_class filter. By adding <?php post_class(); ?> to the div in my loop I was then able to successfully modify the post class. Below is my full code containing the post_class filter and the post_class function. Reference: https://codex.wordpress.org/Function_Reference/post_class ...


0

I think it would be best to do a template override in Woocommerce. If by single you mean a page when viewing only one product then look at the single-product.php template. The directory it needs to located is: /public_html/wp-content/themes/your-theme/woocommerce/single-product.php. You can download the template overrides from woothemes.


2

I tested your all attempts in a shortcode: function add_test_shortcode() { global $wpdb; global $post; $post_ID = $post->ID; $wpdb->show_errors = true; $result = $wpdb->get_var('SELECT meta_value FROM '.$wpdb->postmeta.' WHERE meta_key="my_test" AND post_id=' . $post_ID); return $result; } add_shortcode( 'test', 'add_test_shortcode' ...


1

That is because you're trying to define a property that is already defined, query a table with a wrong name, loop through an integer while you can use get_results instead of query method of $wpdb ... I edited the code, hope it will help with your post duplication process: defined('WP_USE_THEMES') || define('WP_USE_THEMES', false); require_once('wp-load.php'...


0

I would think something is wrong here: $meta = get_post_meta( $post->ID, $extlink , TRUE ); This is the function: get_post_meta( int $post_id, string $key = '', bool $single = false ) You are setting the $extlink as the $key parameter, but it is really a meta key? From your explanation, it seems to be a value of the bookzone key ... If the above ...


0

(EDIT) Take the custom rules outside the # Begin Wordpress (credit to Tim Malone) You can check if the file exists in the root and load it before the Wordpress rules kick in: # check for a file, i.e register.php # load it if found and stop processing the rest of the rules with the [L] flag <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{...


0

Although 61 MB should generally be enough for WordPress, depending on what you're doing you may sometimes need to set the memory limit higher. Creating a menu with a large number of links could well be causing you to hit this limit. Increasing memory allocated to PHP in the Codex explains how can set it higher (as long as it's not blocked by your host), ...


0

I think the answer is "it depends" -- on how flexible and/or "slick" you want the solution to be. The quickest/easiest thing to do would be to create a custom post type (there are tried/true plugins out there that can help establish this) -- and then in your theme functions.php (or in a very simple plugin), put in logic that redirects non-logged in users to ...


0

Never mind, I just took a few hours away from the script and then I found the culprit... I did mistype the $proprietate variable when I assigned it to the db field (which is set to not NULL)...


1

Ok, so I found the solution to this problem and I thought I'd post it here for anyone else who may stumble upon this question. Turns out I was making this much more difficult than it needed to be. I just added a simple function to the custom site plugin I created (this could also be added to your functions.php file). function hea_cpt_author( $query ) { ...


0

Don't use double quotes (") inside the shortcode, since you are using double quotes to specify the href attribute. The browser thinks your href text ends at position=. Use single quotes instead: href="/reservation/?unitrate=[print_csv position='5']&amp;...I agree with the comments that there is a better way to do this, but I provide a potential answer ...


0

Solution, using and statement '&&' for another specific role. Closing <?php if() : ?>, <?php else : ?> Tag with a Column : to be able to post scripts inside the Loop. <?php global $current_user; // Use global get_currentuserinfo(); // Make sure global is set, if not set it. if ( ! user_can( $current_user, "administrator") && ...



Top 50 recent answers are included