Tag Info

New answers tagged

0

Okay, so found the solution (sorry for the delay) I had to put this: // Add Shortcode function city_name() { global $current_cityinfo; return ' '.$current_cityinfo['cityname']; } add_shortcode( 'city name', 'city_name' );


0

Looking for an answer to displaying default text in place of a customizer set heading. In a funny roundabout way, thepost by @Otto gave me the idea of checking for an empty string. <?php if( get_theme_mod( 'tcx_portfolio_intro') == '' ) : ?> <div class="intro"> <h2><?php echo ('nothing here yet'); ?></h2> </div> <?php ...


0

Here's something that should kinda work... in spite of the fact that CPTs don't have a parent category as regular WP posts do. function get_cpt_parent_cat_aka_taxonomy() { global $post; $parent_tax_name = 'Undefined parent taxonomy!'; $obj_taxonomies = get_object_taxonomies( $post->post_type, 'objects' ); $slugs = array(); if( !empty( ...


0

I don't think there's a built-in safe way to do this, but you could directly modify the $wp_styles global after things are registered but before they're output, or at least use it to fetch the parameters a style was originally registered with. global $wp_styles; if( isset( $wp_styles->registered['a_stylesheet'] ) ){ ...


3

You can use PHP get method to process these variables. <?php if( $_GET['action'] == 'discussion' ) { ?> It's True. <?php } else { ?> It's False. <?php { ?>


0

Thank you @TomJNowell, I didn't end up using a reflection class but your answer had enough information regarding classes to get me on the right track. My steps were this. I searched the plugin directory's php files for lines containing the property I wanted to use in my template. grep --include=\*.php -rnw '/path/to/plugin' -e "_some_property" I searched ...


1

The foolproof method here to grab a dynamic member variable is to use reflection! Lets say we have this class: class MyClass { private $myProperty = true; } We can use reflection to acquire the class, and the property: $class = new ReflectionClass("MyClass"); $property = $class->getProperty("myProperty"); We can then set that property to ...


1

If that is the sum of the code for that file then the only place near the bottom is that do_action-- do_action( 'shiroi_after_post_body_content' );-- which looks to be what you want. function test_new_action() { echo 'Howdy'; } add_action('shiroi_after_post_body_content','test_new_action'); Depending upon how this file is included there might be other ...


0

The rewrite rules are wrong. For example, you want to rewrite from community/tag/easter to 'index.php?pagename=community&stencil-tag=easter', so the regex should contain community/tag/ and not only tag/. Also, \d match only digits but the tag value is a string. Same apply to the rewrite for stencil-tag. You could use . to match any character, both ...


0

This is more of a pure PHP than WordPress. You are implicitly creating $ranNum as local variable in function scope. $Example_Widget won't access widget instance in PHP. What you should be using is $this->ranNum, for reading and writing. That will create object's property implicitly, but you likely should declare it explicitly in your class definition ...


1

Don't use globals, but if you must use them you should explicitly declare them as such. Wordpress includes theme files from functions therefor a $test = 1; will be evaluated in the context of the function and the variable $test will be implicitly declared in the context of the function but not as a global.


0

Nevermind, I figured out the solution: the trouble was that POEdit hadn't picked that there were both singular and plural forms, so I had to manually edit the .PE file to this: msgid "Job Posted" msgid_plural "Jobs Posted" msgstr[0] "" msgstr[1] ""


0

You should be passing the 'cityname' to your function: function get_city_name($cityname) { return $cityname; } add_shortcode( 'city-name', 'get_city_name' ); Your shortcode would then look like: [city-name cityname="London"] chances are that your function will return an array, but this should help you move forward


1

You need to get $current_cityinfo first. As in: $current_cityinfo = get_option('current_cityinfo'); Or add this code: global $current_cityinfo; above your return line.


0

Reread your question and revised the solution as well. It is a Page template now and should be set to the page that needs its content protected. It relies on a "login" post that has the html from. <?php /* Template Name: Protected Page */ // Standard HTML of Theme global $post; // check if authentication has been made if( ...


0

And this is why I post to stackexchange. I worked on this for a month, then as soon as I posted the question I found a resolution (Thanks to Milo as well that confirmed my suspicions). The solution was that the script the freelancer had done was trying to call the full URL, and on a localhost it tried to grab the file url. the solution was to replace all ...


2

As you have already understated, running executable PHP inside a text box is not a good idea. It isn't only just not a good idea, but a terrible idea. This creates a loop hole in your security which can be very easily exploited by a hacker. I would suggest writing your own custom widget for this functionality. It is really easy adding a custom sidebar to ...


1

The PHP Code Widget does not modify the Text or Visual editor box, or the standard "Text" widget; it adds a "PHP Code" widget, which you'll find under Appearance > Widgets > Available Widgets. If you want to display your script within the body of the post or page, you should create a Shortcode. The basic example from the API would work for "Hello World"; ...


1

1) That depends on who is building the custom PHP site and how much effort they put into it. If you build a shoddy custom PHP site, then it can easily be hacked. On the other hand, if you don't take certain precautions then your WP site can be hacked too. I just finished up a site for a U.S. Congressman, and their IT guys tried to hack it but couldn't so ...


1

You have a problem with your code formatting and syntax at the very least: function ref_access(){ global $error; if (is_user_logged_in()) // <-- problem here... $newdb = new wpdb( 'user', 'pass', 'db', 'localhost' ); global $newdb; $hf_username = wp_get_current_user(); $inputValue = $_POST[$quanid]; $wpdb->insert( $table, array( 'ItemID' => ...


0

I just should make Method 1 $object->set('meta_key', 'post_views_count'); Method 2 $query->set( 'meta_key', 'post_views_count' ); Method 3 $vars['meta_key'] = 'post_views_count';


-2

I would change this to the following do_shortcode('[button title="EDIT" href="' . edit_product_url( $post->ID ) . '"]');


5

To be honest, if you see yourself in the need of adding executable PHP code into a shortcode attribute, or in content editor in general, you are doing something wrong. You should think again about what, why and how do it. There is a high security risk accepting executable PHP code form user inputs. Instead, you should pass the post ID in shortcode ...


0

Solved it! Hope somebody else can use it or it answers their problem. If there is a better way please share and tell why. $editor_id = 'custom_editor_box'; $uploaded_csv = get_post_meta( $post->ID, 'custom_editor_box', true); wp_editor( $uploaded_csv, $editor_id ); To save the data: function save_wp_editor_fields(){ global $post; ...


0

Well that was tricky. This was the offending code that was generated a line feed to the response. add_action('wp_ajax_nopriv_display_event_info', 'DisplayEventInfoBox'); ?> <?php function displayStepHeader($isValid, $pos) I changed it to add_action('wp_ajax_nopriv_display_event_info', 'DisplayEventInfoBox'); function displayStepHeader($isValid, ...


1

Primary issue with your function is "get_template_part" internally use global $post variable to display the post fields. However, your $post variable is filled for this function only. I would suggest to read this handy article Displaying Posts Using a Custom Select Query Now, specifically in your case function lugaresincreibles_most_commented() { ...


4

It may be because group doesn't exist in the postmeta table. Your meta_key is probably called group and has a meta_value of bicyclegroup. This is assuming you haven't modified the postmeta table. What you could try is: $sql = "SELECT * FROM $wpdb->postmeta WHERE meta_key = 'group' AND meta_value='$group'"; This will return: meta_id post_id meta_key ( ...


1

You are going on the wrong way.This will create difficulties and is NOT WORDPRESS STANDARD.Wordpress has a ajax technique to implement this. Call the ajax from your page <script> var data = { 'action': 'insert_data_customtable', 'first_name': firstname, 'last_name': lastname }; // since 2.8 ajaxurl is always defined in the admin header ...


-1

first of all you need to add enctype="multipart/form-data" to make your form support file uploads. So far you've attached the image to the post, but you haven’t inserted them. Try something like this <?php $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID ); ...


0

Well, it looks like my latest idea proved correct. Simply including the index file for wordpress was enough to get permalinks working for blog posts. $app->slim->notFound(function() use($app) { //to make pretty url's work with turdpress, we must see if that request was intended for our blog route. ...


0

I can't tell what the $my_page, $my_page, or $shipHelper variables are supposed to do, but you can use an output buffer to capture the output of your DisplayEventInfoBox function. You can try the following: function myAJAXFn() { ob_start(); DisplayEventInfoBox($my_page, $shipHelper); $my_html = ob_get_contents(); ob_end_clean(); ...


0

never mind i just figured it out...i had to add a line 'post_type'='contact' and it worked –


0

You cannot move a file over HTTP, instead you need to move it using local path. (e.g. /home/content/site/folders/filename.php). normally people upload files to media library. The following code shows how to upload a file from a plugin. if ($_FILES) { foreach ($_FILES as $file => $array) { if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) { ...


0

It seems the solution I needed was to add this snippet of code to my custom template file for the form page. $pmc = $_GET['pmc']; if($pmc == false){ header('Location: ' . get_bloginfo('url') ); }


1

You have a few options. If you don't want to disable any plugins, try to use the P3 Profiler plugin to identify the plugin or plugins that are slowing down your site. If you don't want to run experiments on your live website, you should make a copy on a sub-domain (you can use the Duplicator plugin for this), make sure the second website is not accessible ...


2

You're sending your AJAX request to the wrong place. Of course calling functions.php directly will get you undefined function errors, because the WordPress API isn't loaded by functions.php ( it's the other way round ). A car doesn't make fuel go forward, fuel makes a car go forward, simply getting in the car won't make fuel magically appear, in the same ...


0

I've been using this .. function get_id_by_slug($page_slug) { $page = get_page_by_path($page_slug); if ($page) { return $page->ID; } else { return null; } } Hope this will help someone.


1

"[C]an you give me all options that are possible"? (emphasis added) No, because HTML, CSS, JS, PHP, and WordPress are powerful and sophisticated. Below are are some different approaches, however. [Affiliation: I am not affiliated with any plugins or programs listed here.] is_user_logged_in() In WP, the level closest to the code is to use the function ...


-1

@toscho's answer is totally wrong. Output buffering can be nested, there's no need to worry about other Plugins. In this post from 2009 there's a very elegant way to fetch and manipulate the final output of Wordpress.


0

Just make sure it's definitely an array before you try to merge it: function minevalg_hent_innstillinger() { $defaults = array(); // define this somewhere; reference it here if ( is_array( $options = get_option( 'minevalg' ) ) ) $options = array_merge( $defaults, $options ); else $options = $defaults; return $options; }


0

One solution would be to create a page with a page template that gets all info based on the user ID. Then you can add that page to the menu. Something like this: <?php /* * Template Name: User Info */ get_header(); //Your code for getting the users id $user_id = '123'; //Output userinfo using your code ... This code shold be saved as a file in ...


1

$metabox is not in the global scope, that is why your two functions is not working. If you turn debug on you will get a a lot of debugging notice error messages regarding the use of $metabox. Simply doing the following $metabox = new Metabox; doesn't make a variable global. It need to be defined as a global. But before you go on and do this, take into ...


1

You'll want to use a PHP if statement in combination with is_user_logged_in If you're editing your header try this: <?php if (!is_user_logged_in()) { ?> // Your social media icons code goes here <?php } ?> The exclamation point before is_user_logged_in() means 'is not' in PHP, so your code essentially says, "If the user is not logged in, show ...


2

A class provides structure, and if it's what you need to do it then do it. The alternative would be a global variable, which is bad practice and should be avoided ( and makes reliable unit testing near impossible ) However, your entire premise is unnecessary. WordPress already stores the option in its caches, so no second database call occurs. Otherwise ...


2

WordPress uses hooks to help developers do what they need to do in a relatively easy way. Some of these hooks are apply_filter() and do_action() which is defined by WordPress. Let's see exactly what happens when we call the_title() all the way up until it hits the hook you defined. <?php the_title(); ?> Developer Resources - the_title() function ...


1

Let's see if we can break it down so it's easy to understand. You have a PHP function named 'cm_title': function cm_title($text) { return 'TESTING &nbsp;' . $text; } It only does 1 thing. It takes what it is given, '$text', and returns that $text with the words 'Testing ' prepended to it. How does WordPress know what '$text' is? It knows/assigns ...


0

any word (html) you put between the single quotes will be echoed when you echo $output. so you can do this: $output .= '<div class="dhvc-woo-view">View: '; $output .= get_post_meta($post->ID, 'pageview', true); $output .= '</div>'; or $output .= '<div class="dhvc-woo-view">'; $output .= 'View: '; $output .= ...


0

Instead of using style background:red; use color:red; like the following. $message = str_replace('{eventlinkURL}',$eventlinkURL,$message); echo "<span style='color:red;'>".$message."</span>";


1

do not use <font> html tag, it is old and i'm not even sure if can work in modern browsers. instead use <span> (for inline text) or <p> (for paragraph). php and html can work together but there's an appropriate way to write it. generally speaking, html code is wrapped with double quotes "html" and php with periods .php.: echo "html code ...



Top 50 recent answers are included