Tag Info

New answers tagged

0

You've got some serious syntax errors - once you open that <?php tag, you're running PHP - no need to execute it again (i.e. inside your variable assignment strings): if ( is_user_logged_in() ) { // Only show the output below if a user is logged in $admin_link = esc_url( admin_url() ); // Escaped admin link $logout_link = esc_url( ...


0

You can just list them as a list regularly, and style them with css li:nth-child(even) { background: #000 } li:nth-child(odd) { background: #CCC } If you are worried about browser support you could add different classes when you're populating the list in PHP using $i or something like for($i = 0; $i < count($list); $i++) { echo '<li class="'.($i ...


0

First of all you have to start log views of each post. You can do it by yourself or by a plugin. Here you have an example how you can track this number without any plugin. Add this code to the theme's functions.php file function prefix_get_post_views( $post_id ){ $count_key = 'post_views_count'; $count = get_post_meta( $post_id, $count_key, true ); ...


2

the_permalink() function doesn't return the post permalik, it prints the permalink. To assing the permalink value to $url variable you need to user get_the_permalink() instead: $url = get_the_permalink();


0

You're not handling the names the same way as the other fields: //// VERIFIES CREDENTIALS $username = isset($_POST['username']) ? trim($_POST['username']) : ''; $first_name = isset($fields['user_first_name']) ? sanitize_text_field(trim($fields['user_first_name'])) : ''; $last_name = isset($fields['user_last_name']) ? ...


2

The limitation is down to the existing arguments and how pretty much all widgets typically output content: echo $args['before_widget']; if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; } // Widget content echo $args['after_widget']; Some widgets may offer before/after content hooks, but if you want a "global" fix there's ...


0

Ok, As it's front-end... I might: Set up the folder on the server so that WordPress can read/write (775 or 755 ordinarily works depending on how your server is configured in terms of user/group permissions). Allow a user on the front end to see the files or choose which file to delete Upon choosing the file, pass the parameter to an intermediary PHP ...


0

$args = array( "label" => "Butik Categories", "singular_label" => "Butik Category", 'public' => true, 'hierarchical' => true, 'show_ui' => true, 'show_in_nav_menus' => false, 'args' ...


1

That is not the way to register a Taxonomy.Please find the code below to register a Taxonomy for a custom post type :- $args = array( "label" => "Butik Categories", "singular_label" => "Butik Category", 'public' => true, 'hierarchical' => true, ...


0

You will need to use a hook (such as init or admin_init) to detect whether a condition has been met. For instance, the existence of a certain querystring variable (which can be a url encoded url, if you like). When the condition is met, use wp_safe_redirect() (and optionally exit()) to redirect to the URL you want. You can either hard-code that URL or fetch ...


0

If you want to display all products with a number you can use this (I suppose that $total_items_of_order is an array): foreach ($total_items_of_order as $key => $value) { echo $key + 1 . $value; } If you want to handle in other way, you can use this syntax and handle the array as you want


0

Copy the file to your child theme, In your child theme, create a template and name it what ever you want, e.g content-child.php Now you can replace lib/login/register.php with your new template: <?php get_template_part( 'content-child', get_post_format() ); ?> It should work.


0

As per GentlemanMax's comment, you'll want a table. There's a really useful guide in the Codex (which also goes into how to do DB upgrades / migrations.) One thing I'd emphasise: make sure to use $wpdb->prefix in the table name because not all sites will have tables beginning wp_*. Also, if you're ever planning to distribute your plugins to other ...


0

First thing is the add rewrite rule function. You have - add_rewrite_rule('^wp-api/pugs/?([0-9]+)?/?','index.php?__wp-api=1&pugs=$matches[1]','top'); wp-api/pugs/?([0-9]+) this means, when you request <url>/wp-api/pugs/123, you will get a query variable pugs with parameter 123. $var = get_query_var('pugs'); // = 123 Now, you don't really need ...


0

You can try this $mailer = WC()->mailer(); $mails = $mailer->get_emails(); if ( ! empty( $mails ) ) { foreach ( $mails as $mail ) { if ( $mail->id == 'customer_completed_order' ) { $mail->trigger( $order->id ); } } }


0

As you are building a page template, you can insert in the content of that template whatever you want and use any PHP snippet you want. So, you can continue doing it as you was doing in PHP. For example, this could be your page template: <?php /* Template Name: My template */ get_header(); ?> <main> <?php if( isset( $_GET['pid'] ) ...


0

I might be missing something but: If you only need the 'pid' for example and it is part of the URL then its fairly simple? In the page template 'examplepage' just do a: $mypid = $_GET['pid']; in there and then carry on with the SQL query based on that value and echo out a response. If you want something a little more ajax based then when the user lands ...


1

As you have already pointed out in your question, custom taxonomies are the way to go here. For this taxonomy to behave like the build in taxonomy post_tag, you need to set the hierarchical parameter to false. To make these taxonomy available to only your two specific post types, you need to specifiy this when registering your taxonomy. Example ...


1

That's normal and expected inside the wp-content, themes, and plugins directories. Their presence is to prevent listing of directory contents if people navigate to those directories via http. There's nothing wrong there and no fix is required.


4

It's a PHP callback. You need the syntax to keep a reference to the class instance. Put it this way - if you didn't have $this, how does the caller know that getStuffDone is a method of your class, and not just a regular PHP function? It doesn't. Using array( $this, 'getStuffDone' ) says to PHP: Hey bro, you need to call the method getStuffDone on ...


3

the add_action() function definition looks like: function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) { return add_filter($tag, $function_to_add, $priority, $accepted_args); } so according to that it looks like it expects (string,string,int,int) In a traditional php file the second parameter would simply be one of your ...


2

Your custom loop $catquery will override the "current" post, and so the_field will operate on the last post of that loop. Call wp_reset_postdata() right after your loop is finished (after endwhile;). This will restore the post global to the true "current" post.


0

Since noone responded, here's my solution: I copied my menubar from header.php into a new file called menubar.php and called that file with include("menubar.php");


1

I would suggest querying a list of all post types using get_post_types. With that array you can do a foreach. and for each post type, query all terms with get_term. It would look something like this, but you should pass get_post_types your know post types, because as it stands, this will also display things like attachments and nav menus. function ...


1

get_term_link() will return a WP_Error object on error. You can't print an object or array or you will get messages similar to what you are getting. Use var_dump() instead or print_r() and you should see what is occuring. Your error even tells you that WP_Error is the object involved. You are getting errors when the term you are looking for is not found. ...


4

You can use the category__in argument: // use get_the_category( $post_id ) if you are outside the loop $categories = get_the_category(); if( $categories ){ $related_posts = get_posts( array( 'category__in' => $categories ) ); }


2

As for your PHP not being executed - the action parameter in your JavaScript AJAX call needs to match the hook name in your add_action call. Take a look at the example below. I haven't tested it but it should work. I have simplifed the AJAX call, feel free to modify it to suit your use case. var data = { action: 'jk-author-follow', // Look Ma' I talk to ...


-1

Found a method! echo '<META HTTP-EQUIV="REFRESH" CONTENT="3">' ;


0

Add below code to your functions.php function add_script_and_style() { // for .css add wp_enqueue_style('my-style', get_template_directory_uri() . '/my_style.css'); // for .js add wp_enqueue_script( 'my-js', get_template_directory_uri() .'/filename.js', false ); } add_action( 'wp_enqueue_scripts', ...


0

CSS links are relative to the current request URI, not your PHP file. Use an absolute path like: <link rel="stylesheet" href="<?php bloginfo( 'template_url' ) ?>/themesubfolder/style.css" />


0

This is mostly a case of trusting the arguments. Or not trusting. You can assume that you have received meaningful arguments, ready to be used. You can assume they are arbitrary and possibly grossly invalid. I would say in this specific case it hangs if the code is public or private. In private site you have the full control over it, from sidebar ...


0

You'd need to put the variable's value onto the page so that javascript can pass it back to PHP using ajax. Ajax functions are a completely separate "page load" so even if you made it global it won't work. The best way to do this is using "wp_localize_script" (https://codex.wordpress.org/Function_Reference/wp_localize_script) Here's an full example of how ...


0

What about putting the city/regions/whatever into an array you can loop through? Something like this: $cities = array( 'Richmond', 'Chicago', 'New York' ); foreach ( $cities as $city ) { ?> <h2><?php echo $city; ?></h2> <ul><?php foreach ( get_users_by_meta_data( 'school_division', $city ) as $user ) { ?> ...


0

First you should make some improvements to your template file. Try this: <?php get_header(); ?> <?php global $woo_options; ?> <?php if ( $woo_options['woo_featured_disable'] <> "true" ) include( TEMPLATEPATH . '/includes/featured.php'); ?> <?php $args = array( 'post_type' => 'infobox', 'order' => 'DESC', // DESC for ...


0

Just use the $product parameter to get the custom field value, and determine what to return: function custom_price_html( $price, $product ) { if ( ( int ) get_post_meta( $product->id, 'price_per_person', true ) ) $price .= ' per person'; elseif ( ( int ) get_post_meta( $product->id, 'price_per_group', true ) ) $price .= ' per ...


3

The insert method of $wpdb already scapes the data taking care of SQL injection. What you should worry about is about data sanitization and validation. For exmpla: Sanitization What type of data do you accept in $votes? A integer value? If so, be sure $votes contains a integer value. You cuold do it, for exmaple, using intval function from PHP. This is ...


2

wpdb::insert already protects against SQL injection, it's a wrapper for wpdb::prepare For insert(), you can pass a third "formats" argument for extra sanitization: $wpdb->insert( 'votes', array( 'votes' => $votes, 'competition' => $competition, 'uid' => $uid ), array( '%s', // $votes will ...


1

Try something like this, which would save in transient for 12 hours. Let me know if anything does not make sense. <?php $value = get_transient( 'value' ); if ( false === $value ) { $output = ""; $html = file_get_contents('http://www.example.com'); $doc = new DOMDocument(); libxml_use_internal_errors(TRUE); // disable libxml errors ...


0

Could you go to this page for us: ../wp-admin/options-permalink.php What is the structure chosen? That will give you the answer for how to adjust the function on the bottom edit: Also, Why is this part like this: if ($echo) { echo $output; } return $output; } Shouldn't $output be in parenthesis?


0

The wp_get_archives function in Wordpress does not support displaying dates. However my solution worked without using this function it's still probably handy for your or someone else his cause: In the functions.php file of your theme place the following: function recentPostsDate() { $rPosts = new WP_Query(); $rPosts->query('showposts=6'); ...


0

As noted in https://github.com/wp-cli/wp-cli/issues/1754#issuecomment-91361340, I figured this one out. It turns out it wasn't wp-cli's fault at all. My confusion arose from the fact that I'm running a web server with nginx and php fpm, which has it's own php.ini . wp commands run php (cli) directly on the host and so the config can be different. In this ...


0

Move insert query to top of file. So it will select updated data. <?php // Save form data if(isset($_POST['submit'])){ global $wpdb; $votes = 1; $competition = $_POST['comp']; $uid = $_POST['id']; //$uid = get_current_user_id(); echo 'id of image = '.$_POST['id']; echo '<br>'.'competition is'.$_POST['comp']; if($wpdb->insert( ...


0

Well, it is quite a hack I propose, but I would suggest the following: add_action( 'admin_head', 'chg_menu_on_special_pages_page' ); function chg_menu_on_special_pages_page(){ global $parent_file; $gallery_page_id = 2; if( $parent_file != 'edit.php?post_type=page' ) return; if( ! isset( $_GET['post'] ) || $_GET['post'] != ...


0

Perhaps you could define a function which just pulls in the post.php content and set it as your callback for add_menu_page(). But the slug parameter is not meant to accept variables. You will need to modify the $_REQUEST array to achieve that. Ex: add_menu_page( __( 'Gallery', '' ), __( 'Gallery', '' ), 'edit_posts', 'gallery-edit', 'gallery-edit-page', ...


0

Maybe not the most elegant solution $authorPost = get_posts(array('author' => 1));foreach ($catPost as $post) { setup_postdata($post); $ids[] = get_the_ID(); } $idList = implode(",", $ids); //turn the array into a comma delimited list $meta_key = 'post_view'; $allview = $wpdb->get_var($wpdb->prepare(" SELECT ...


1

Like your sample: $results = array( (object)array('id'=>1, ...


0

Here is the hard core coding for the simple answer. Use this code to attach a video to the post. I have given a static $listing_post_id post id equal to 7. You can use dynamical post id here. Other wise code is working and tested. Validation is not done here you can do it as you wish. <?php if (isset($_POST['uploadvideo'])) { if ( ! function_exists( ...


0

This was happening because of a woocommerce.php file in theme's root folder, that was overriding a lot of stuff, including single-product.php, via woocommerce_content() function. As redelshaap and woocommerce's documentation say, this is not the best way to implement theme compatibility and customization... ...


0

wordpress uses <!--next page--> as a hint to paginate the content of a post only when it is in a content of a post. Your code produce direct HTML code in which <!--next page--> is just an html comment.


0

I just started posting here so I cannot comment below your comments on JD Cutter's feed, but I wanted to add something that might help. The header.php and footer.php are usually something that will appear on every page so you can rule those out if your edits are not on the header or footer. The page.php and single.php are usually the default template to ...



Top 50 recent answers are included