Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

Simba123 on "SQL sum of custom field split into months"

$
0
0

Hi,
I have two parts to my question.

1. I have Advanced Custom Fields installed and I am using that to build an accounting system for myself.

I'm working on the cashflow page and I need to show total money in per month and year automatically. eg. April 2015, Total money in is £100.

My custom field (number) 'total_invoice_cost' is what gets the figure (£100). I have another custom field (text) 'paid' which will have the options 'yes' 'no' and 'overdue'

I need a way to show month by month the sum of invoices which have a figure inputted and are set to yes.

Here is what I have so far:

<?php
$meta_key = 'total_invoice_cost';
$annualincome = $wpdb->get_var( $wpdb->prepare(
	"
		SELECT sum(meta_value)
		FROM $wpdb->postmeta
		WHERE meta_key = %s

	",
	$meta_key
) );
echo "<p>Total money in this year is {$annualincome}</p>";
?>

This shows the sum of all the 'total_invoice_cost' fields filled out and it isn't broken up by month either.

So what needs to be done is only add if the custom field 'paid' is set to 'yes' and to also filter by month automatically.

2. How can I show the sum of 'total_invoice_cost' by itself for the current month? So the code above is nearly there for this part of the question, I just need it to show the total for the current month (and changing automatically) so I can keep track of money due in.

I hope this all makes sense, any help would be much appreciated.


Eky Divine on "Sudden Hike in Visits"

$
0
0

Good day,

Please I need your help in a new event that has happened on my blog, I've asked for assistance but am too eager and haven't gotten any response from the team.

I have a sudden hike in visits today on my blog and the hike is too much and while and excited am also worried as I feel my blog is in danger and is exposed to trouble.

Kindly help look into my account and see why I have such a huge count on visits. On an average of 250 visitors I have 2500 visits and now I have 280 visiots with above 220,000 visits. This is too sudden and too shocking and I feel there is a problem somewhere.

I hope to hear from you real soon as am worried about something happening to my blog.

Thank you,

Eky Divine

GeekServe on "Custom taxonomy and post type not working as expected"

$
0
0

Hi all,

I am trying to create a custom Post Type and Taxonomy that will work with the permalink structure of: /mod-slug/taxonomy-name/child-taxonomy-name/post-name

However, with the following code, I am only able to access posts like the following:

/slug/post-name

I was wondering if someone could point out what I have done wrong here

<?php

    /*
     * Plugin Name: Mod post type
     * Version: 1.0.
     * Plugin URI:
     * Description: A custom posttype to facilitate modifications
     * Author: Jake
     * Author URI:
     * Requires at least: 3.9
     * Tested up to: 4.2.1
     *
     * @package WordPress
     * @author Jake
     * @since 1.0.0
     */

    if ( ! function_exists('register_mod_posttype') ) {

    function create_my_taxonomies() {
        register_taxonomy(
            'rw_mod_category',
            'rw_mod_post',
            array(
                'labels' => array(
                    'name' => 'Mod Categories',
                    'add_new_item' => 'Add New Mod Category',
                    'new_item_name' => "New Mod Category"
                ),
                'rewrite' => array(
                    'slug' => 'mods', // This controls the base slug that will display before each term
                    'with_front' => true, // Don't display the category base before "/locations/"
                    'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
                  ),
                'show_ui' => true,
                'show_tagcloud' => false,
                'hierarchical' => true
            )
        );
    }

    // Register Custom Post Type
    function register_mod_posttype() {

        $labels = array(
            'name'                => _x( 'Mods', 'Post Type General Name', 'mods_domain' ),
            'singular_name'       => _x( 'Mod', 'Post Type Singular Name', 'mods_domain' ),
            'menu_name'           => __( 'Mod', 'mods_domain' ),
            'name_admin_bar'      => __( 'Mods', 'mods_domain' ),
            'parent_item_colon'   => __( 'Parent Mod:', 'mods_domain' ),
            'all_items'           => __( 'All Mods', 'mods_domain' ),
            'add_new_item'        => __( 'Add New Mod', 'mods_domain' ),
            'add_new'             => __( 'Add New', 'mods_domain' ),
            'new_item'            => __( 'New Mod', 'mods_domain' ),
            'edit_item'           => __( 'Edit Mod', 'mods_domain' ),
            'update_item'         => __( 'Update Mod', 'mods_domain' ),
            'view_item'           => __( 'View Mod', 'mods_domain' ),
            'search_items'        => __( 'Search Mod', 'mods_domain' ),
            'not_found'           => __( 'Not found', 'mods_domain' ),
            'not_found_in_trash'  => __( 'Not found in Trash', 'mods_domain' ),
        );
        $args = array(
            'label'               => __( 'mod', 'mods_domain' ),
            'description'         => __( 'Mods being posted to the site', 'mods_domain' ),
            'labels'              => $labels,
            'supports'            => array( 'title', 'editor', 'author', 'thumbnail', 'revisions', 'custom-fields', 'page-attributes', ),
            'taxonomies'          => array( 'rw_mod_category', 'post_tag' ),
            'hierarchical'        => false,
            'public'              => true,
            'show_ui'             => true,
            'show_in_menu'        => true,
            'menu_position'       => 5,
            'menu_icon'           => 'dashicons-admin-tools',
            'show_in_admin_bar'   => true,
            'show_in_nav_menus'   => true,
            'can_export'          => true,
            'has_archive'         => true,
            'exclude_from_search' => false,
            'publicly_queryable'  => true,
            'capability_type'     => 'page',
                    'rewrite'     => array('slug' => 'mods'),
        );
        register_post_type( 'rw_mod_post', $args );

    }

    // Hook into the 'init' action
    add_action( 'init', 'register_mod_posttype', 0 );

    add_action( 'init', 'create_my_taxonomies', 0 );
    }

Any help would be greatly appreciated,

Jake

Rafael Segat on "Update Options Settings"

$
0
0

Hey guys,

I'm with a huge problem to my plugin. Some users can update the options and others can't. All users are using the same WordPress version.

I'm using this function to update my options.

<br />
/**<br />
         * Retrieve the stored plugin option or the default if no user specified value is defined<br />
         *<br />
         * @param string $option_name The name of the option you wish to retrieve<br />
         *<br />
         * @uses get_option()<br />
         *<br />
         * @return mixed Returns the option value or false(boolean) if the option is not found<br />
         */<br />
        function get_option( $option_name, $reload = false ) {</p>
<p>            // If reload is true, kill the existing options value so it gets fetched fresh.<br />
            if( $reload )<br />
                $this->options = null;</p>
<p>            // Load option values if they haven't been loaded already<br />
            if( !isset( $this->options ) || empty( $this->options ) ) {<br />
                $this->options = get_option( $this->option_name );<br />
            }</p>
<p>            if( isset( $this->options[$option_name] ) ) {</p>
<p>                return $this->options[$option_name];    // Return user's specified option value</p>
<p>            }else{</p>
<p>                return "";</p>
<p>            }<br />
            //} elseif( isset( $this->defaults[$option_name] ) ) {</p>
<p>            //    return $this->defaults[$option_name];   // Return default option value</p>
<p>            //}<br />
            //return false;<br />
        }</p>
<p>         /**<br />
         * Route the user based off of environment conditions<br />
         *<br />
         * This function will handling routing of form submissions to the appropriate<br />
         * form processor.<br />
         *<br />
         * @uses RelatedServiceComments::_admin_options_update()<br />
         */<br />
        function route() {<br />
            $uri = $_SERVER['REQUEST_URI'];<br />
            $protocol = isset( $_SERVER['HTTPS'] ) ? 'https' : 'http';<br />
            $hostname = $_SERVER['HTTP_HOST'];<br />
            $url = "{$protocol}://{$hostname}{$uri}";<br />
            $is_post = (bool) ( strtoupper( $_SERVER['REQUEST_METHOD'] ) == "POST" );</p>
<p>            // Check if a nonce was passed in the request<br />
            if( isset( $_REQUEST['_wpnonce'] ) ) {<br />
                $nonce = $_REQUEST['_wpnonce'];</p>
<p>                // Handle POST requests<br />
                if( $is_post ) {<br />
                    if( wp_verify_nonce( $nonce, "{$this->namespace}-update-options" ) ) {<br />
                        $this->_admin_options_update();<br />
                    }<br />
                }<br />
                // Handle GET requests<br />
                else {<br />
                    // Nothing here yet...<br />
                }<br />
            }<br />
        }</p>
<p>         /**<br />
         * Process update page form submissions<br />
         *<br />
         * @uses RelatedServiceComments::sanitize()<br />
         * @uses wp_redirect()<br />
         * @uses wp_verify_nonce()<br />
         */<br />
         function _admin_options_update() {<br />
            // Verify submission for processing using wp_nonce<br />
            if( wp_verify_nonce( $_REQUEST['_wpnonce'], "{$this->namespace}-update-options" ) ) {<br />
                $data = array();<br />
                /**<br />
                 * Loop through each POSTed value and sanitize it to protect against malicious code. Please<br />
                 * note that rich text (or full HTML fields) should not be processed by this function and<br />
                 * dealt with directly.<br />
                 */<br />
                foreach( $_POST['data'] as $key => $val ) {</p>
<p>                    $data[$key] = $this->_sanitize( $val );<br />
                }</p>
<p>                // Update the options value with the data submitted<br />
                update_option( $this->option_name, $data );</p>
<p>                // Redirect back to the options page with the message flag to show the saved message<br />
                wp_safe_redirect( $_REQUEST['_wp_http_referer'] );<br />
                exit;<br />
            }<br />
        }</p>
<p>        /**<br />
         * Sanitize data<br />
         *<br />
         * @param mixed $str The data to be sanitized<br />
         *<br />
         * @uses wp_kses()<br />
         *<br />
         * @return mixed The sanitized version of the data<br />
         */<br />
        function _sanitize( $str ) {<br />
            if ( !function_exists( 'wp_kses' ) ) {<br />
                require_once( ABSPATH . 'wp-includes/kses.php' );<br />
            }<br />
            global $allowedposttags;<br />
            global $allowedprotocols;</p>
<p>            if ( is_string( $str ) ) {<br />
                $str = wp_kses( $str, $allowedposttags, $allowedprotocols );<br />
            } elseif( is_array( $str ) ) {<br />
                $arr = array();<br />
                foreach( (array) $str as $key => $val ) {<br />
                    $arr[$key] = $this->_sanitize( $val );<br />
                }<br />
                $str = $arr;<br />
            }</p>
<p>            return $str;<br />
        }<br />

ald0413 on "If no comments"

$
0
0

HI,

My client would like it if I could only show the number of comments if there are actually comments.

I have tried the function reference from this page, https://codex.wordpress.org/Function_Reference/have_comments, but it doesn't work, and it references twentyten, so I fear the information is out of date.

Would someone be able to point me in the right direction?

dbrewerton on "JavaScript redirection if then structure with IE"

$
0
0

This is really frustrating me so hopefully someone can help. I am trying to use a landing page which should check for the browser the user is using. If it is IE, go to a post optimized for IE, else go to a standard post. I have tried a variety of different ones, either the script does not do anything or it redirects to the wrong one in IE. Can someone give me a sample? I need it to work with all versions of IE - non-version specific.

CK 57 on "How to edit hack from site?"

$
0
0

I viewed my site with Google Chrome view source.http and finally found the entries where my site is hacked. I have this in notepad currently. When I go to Wordpress and view the sections I am not able to find the same text? I am not sure how much to delete, and then what steps to take to reload the file? Shouldn't I be able to make the edits within Wordpress? It looks as though the text below was added:
payday loans and check casing peral city
Then there is a line </div> <div id="bd" class="yui-navset">
Does that line need to go also and some other lines witht he reference to "yui-g"
I am not skilled WP user and really stretching to explain or fix this. Any help appreciated

woalmoore on "Page as parent of category"

$
0
0

You could either do a custom template that include the get_posts template function or the get_posts plugin to accomplish this. (probably the latter as it allows you to use a shortcode directly in the page rather than needing to have a different template for each of your category pages).


ahnuts on "Overwrite query for page template?"

$
0
0

I have a function that is creating subdomains based on specific pages. So solutions.mywordpresssite.com is loading the content from http://www.mywordpresssite.com/solutions/. I'm doing this by overwriting the query_posts() and matching the subdomain to the subfolder. The problem is, solutions.mywordpressite.com still thinks it's the homepage. It is displaying the correct content from /solutions/, but the template and other data is all being pulled directly from the static homepage. Is there a way that I can tell my subdomain to pull the rest of the data from the /solutions/ page as well?

Call_Me_Matthew on "How to assign a Page Template to certain URL Patterns?"

$
0
0

Is there a way to set up a page template that assigns itself to pages of a particular url structure?

For example, say you have these urls:

http://www.mysite.com/beachhouse/snippet
http://www.mysite.com/hospital/snippet
http://www.mysite.com/farm/snippet
http://www.mysite.com/mansion/snippet

I don't want to have to create pages manually for every "snippet' subpage on my site. Instead, I want to create a page template that will load automatically when a url with a pattern of "http://mysite.com/x/snippet" is visited.

I've already created a template file that loads content dynamically depending on the parent page(it takes the parent's slug from the url and serves up content based on that). I just need help figuring out how to assign it to a specific url pattern, as opposed to a page.

Thanks for any help!

ciscothehellspawn on "Customize password protected page"

$
0
0

Hi, I need help to customize a password protected page:

HERE's THE PAGE

This error page is generated from ../wp-includes/functions.php

</head>
<body id="error-page">
<?php endif; // ! did_action( 'admin_head' ) ?>
	<?php echo $message; ?>
</body>
</html>

Probably the $message comes from the plugin I used to manage a file download.

I know I can modify the css, but I would like to add a message in the wrong password case... How?

Thank you in advance

mxm.k.marquette on "Hi i want to exclude a category"

$
0
0

hi i just setup a random post thingy in my wordpress

<?php
add_action('init','random_add_rewrite');
function random_add_rewrite() {
global $wp;
$wp->add_query_var('random');
add_rewrite_rule('random/?$', 'index.php?random=1', 'top');
}
add_action('template_redirect','random_template');
function random_template() {
if (get_query_var('random') == 1) {
$posts = get_posts('post_type=post&orderby=rand&numberposts=1');
foreach($posts as $post) {
$link = get_permalink($post);
}
wp_redirect($link,307);
exit;
}
}
?>

and i want to exclude a category from the random link thingy is that possible ? and how to do it

Looic on "Wordpress CLI : Exclude plugin from loading"

$
0
0

Hi All,

I am developping a plugin that needs to be loaded in command-line. The Wordpress environment loads successfully and I can create / update posts from the commandine.

Now, I would like to prevent some plugins to load automatically when I load the wordpress environment from commandline.

Is there a way to prevent some plugins to load only when Wordpress is called in commandline ?

Thank you for your help,
Looic.

retrosmith on "Can't login"

$
0
0

I wasn't hacked but I can't login? If I was hacked my site would have been taken down but it's still up. I don't think even the NSA could crack my password without a backdoor. Also when I send a confirmation email to my address the link to reset my password is broken? Wtf? Can someone please help me! thank you

btgjp on "GUID column issues."

$
0
0

I an using the guid cloumn to store a uuid. I also added a uuid column to the post table as a backup if there was ever a problem. After a recent update WP is prepending my UUID value with "http://".

For example "2C3467A6-2765-478F-81C9-8013F1D623B9" becomes "http://2C3467A6-2765-478F-81C9-8013F1D623B9"

This is causing some problems and I need to fix it. Below is the function I am using to do this.

function wpufe_update_uuid( $post_id ) {

	$uuid = get_post_meta( $post_id, '_uuid', true );
	global $wpdb;
	$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET guid = %s WHERE ID = %d", $uuid, $post_id ) );
	$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET uuid = %s WHERE ID = %d", $uuid, $post_id ) );

	}

add_action( 'wpuf_add_post_after_insert', 'wpufe_update_uuid' );
add_action( 'wpuf_edit_post_after_update', 'wpufe_update_uuid' );

Looic on "Archive taxonomy terms by first letter"

$
0
0

Hi,

I built an archive page that displays a list of taxonomy terms, related to one custom taxonomy. Now, there are so many taxonomy terms that I would like to filter them by term first letter.

How could I modify the Query before it is parsed - for example through pre_get_posts - so that it displays only terms by the first letter selected ?

Thank you,
Looic.

jaycbrf on "Trying to create shortcode/plugin for Bootstrap Carousel"

$
0
0

I am trying to create a plugin for my theme to use a custom post type "carousel-images" and the shortcode [carousel] to create a carousel of featured images.

Currently the first image shows up with the Bootstrap Carousel navigation and prev/next icons, but the carousel will not scroll or show any additional images. There are 3 posts with featured images for the carousel.

here is my plugin.php

<?php
        /*
        Plugin Name: WP_BS_Carousel
        Description: Bootstrap Carousel Custom Post-Type
        Author: Jaycbrf4
        Version: 1.0
        /*/

        function wp_bs_theme_setup() {
           add_theme_support( 'post-thumbnails' );
            add_image_size( 'wp_bs_carousel_image', 1170, 385, true);
        }
        add_action( 'after_setup_theme', 'wp_bs_theme_setup' );

        // Creates Carousel Image Custom Post Type
            add_action( 'init', 'register_wp_bs_carousel_image' );
            function register_wp_bs_carousel_image() {
            $labels = array(
            'name' => _x( 'Carousel Images', 'carousel_image' ),
            'singular_name' => _x( 'Carousel Image', 'carousel_image' ),
            'add_new' => _x( 'Add New', 'carousel_image' ),
            'add_new_item' => _x( 'Add New Carousel Image', 'carousel_image' ),
            'edit_item' => _x( 'Edit Carousel Image', 'carousel_image' ),
            'new_item' => _x( 'New Carousel Image', 'carousel_image' ),
            'view_item' => _x( 'View Carousel Image', 'carousel_image' ),
            'search_items' => _x( 'Search Carousel Images', 'carousel_image' ),
            'not_found' => _x( 'No carousel images found', 'carousel_image' ),
            'not_found_in_trash' => _x( 'No carousel images found in Trash', 'carousel_image' ),
            'parent_item_colon' => _x( 'Parent Carousel Image:', 'carousel_image' ),
            'menu_name' => _x( 'Carousel Images', 'carousel_image' ),
            );
            $args = array(
            'labels' => $labels,
            'hierarchical' => false,
            'description' => 'Images for Bootsrap Carousel',
            'supports' => array( 'title', 'editor', 'thumbnail','excerpt' ),
            'taxonomies' => array( 'category' ),
            'public' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'menu_position' => 20,
            'menu_icon' => 'dashicons-images-alt',
            'show_in_nav_menus' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'has_archive' => true,
            'query_var' => true,
            'can_export' => true,
            'rewrite' => true,
            'capability_type' => 'post'
            );
            register_post_type( 'carousel-image', $args );
            }

        function wp_bs_carousel($atts) {
           // Set Shortcode Attributes
           extract(shortcode_atts(array(
              'posts' => 1,
           ), $atts));

           // Start the Return String
           $return_string = '<div id="wp_bs_carousel" class="carousel slide carousel-fade"  data-ride="carousel">

           <!-- Indicators -->
          <ol class="carousel-indicators" >
            <li data-target="#wp_bs_carousel" data-slide-to="0" class="active"></li>
            <li data-target="#wp_bs_carousel" data-slide-to="1"></li>
            <li data-target="#wp_bs_carousel" data-slide-to="2"></li>
          </ol>

         <div class="carousel-inner" >';

           // The query
           $the_query = new WP_Query(array(
           'post_type' => 'carousel-image',
            'posts_per_page' => 1
            ));

           // The loop
           while ( $the_query->have_posts() ) :
              $the_query->the_post();
              $return_string .= '<div class="item active">'.get_the_post_thumbnail($post->ID,'wp_bs_carousel_image').'<div class="carousel-caption">
            <h1>'.get_the_title().'</h1>
            <p>'.get_the_excerpt().'</p>
           </div>
           </div><!-- item active -->';
           endwhile;
           wp_reset_postdata();
           $the_query = new WP_Query(array(
            'post-type' => 'carousel-image',
            'posts_per_page' => $posts,
            'offset' => 1
            ));
           while ( $the_query->have_posts() ) :
           $the_query->the_post();
          $return_string  .= '<div class="item">'.the_post_thumbnail('wp_bs_carousel_image').'<div class="carousel-caption">
            <h1>'.the_title().'</h1>
            <p>'.the_excerpt().'</p>
           </div>
           </div><!-- item -->';
           endwhile;
           wp_reset_postdata();

           // Finish the Return String and Clean Up
           $return_string .= '</div>

             <!-- Controls -->
          <a class="left carousel-control" href="#wp_bs_carousel" role="button" data-slide="prev">
            <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
            <span class="sr-only">Previous</span>
          </a>
          <a class="right carousel-control" href="#wp_bs_carousel" role="button" data-slide="next">
            <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
            <span class="sr-only">Next</span>
          </a>
        </div>';

           return $return_string;
        }

        add_shortcode('carousel', 'wp_bs_carousel');

        ?>

anbu369 on "Post views for every month"

$
0
0

Hi, I am developing a plugin to show a leaderboard which will show the authors with more page views. I need to have the overall page views in the database and also create table entries for page views in every month separately so I could rank the authors for that month. How should I do it?

gmassard on "Related Pages instead of Related Posts?"

$
0
0

Hi.

Is it possible to add a "Related Pages" option at the bottom of my static pages? If so, what is the procedure? Thanks in advance.

Tatiane Pires on "Add permalink to yearly, monthly and daily archives for Custom Post Types"

$
0
0

I'd like to add a permalink to redirect to yearly, monthly and daily archives of a custom post type.

Example:
tatianepires.com.br/en/2015
- 'en' is the slug for the CPT
- I'd like the link above to load yearly archive page for that post type
- the link above goes to 404 error page =(

Here is the code for the mu-plugin that registers the CPT:
href="http://pastebin.com/8iRm0pSC">http://pastebin.com/8iRm0pSC

I've read the following Codex pages trying to find a way to get this working:
codex.wordpress.org/Function_Reference/add_permastruct
codex.wordpress.org/Rewrite_API/add_rewrite_rule
codex.wordpress.org/Rewrite_API/add_rewrite_tag
codex.wordpress.org/Function_Reference/get_query_var
codex.wordpress.org/WordPress_Query_Vars

Help is appreciated. Tks.

Viewing all 8245 articles
Browse latest View live


Latest Images