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

RubyNet on "Need help to get rid of Trailing Link: Copy and WIN : [removed]"

$
0
0

Hello..

Anytime i copy a sentence from my website, it has this trailing link:

Copy and WIN : [removed]

For example, If i copy (ctrl C) the word James is a boy and paste on any platform form, it becomes:

James is a boy
Copy and WIN : [removed]

Any idea on how i might get rid of it will be much appreciate.


dennishall on "Plugin development: Insert current_user into javacript"

$
0
0

Hi:
I'm developing a plugin that contains 8 form fields. 2 or the form fields currently need the user to enter their first and last names. I would like to automate this and remove the fields all together by having my javascript get the first and last names of the logged in user.

I'm hoping to make use of the $current_user function(s) but I'm not clear on how I could do it in WP.

Is this possible to do within my plugins javascript?
Any help or code snippet would be great.

BestRegards,
Dennis Hall

gicolek on "Calculating Match ratio, based on CPT with ACF custom fields."

$
0
0

Hey guys,

I have a troublesome feature request for which I can't find the optimal solution.

Basically there's a CPT Match which has several ACF custom fields, that give one the ability to specify the outcome of each match.

The custom set up goes as follows:

Each Match can have a winner specified, which is a simple select of all available Teams. Each Team is stored as a Custom Taxonomy.

There are two checkboxes Draw and Pending.

Now each user can specify the outcome of any match before it has occured, say one can bet on the outcome.

Based on his bets and the real outcome I'm to calculate the win / lose ratio for each user Tipps to verify his credibility.

This ratio is then printed out below each Match based on the user data provided.

My main issue here is the fact that I can't simply fetch all the matches from the DB and then calculate the ratio.

Why?

Because the query may be extremely slow with increasing volume of posts.
Matches that were cancelled should be remove from this ratio.

Have you any suggestion on the best approach to that problem?

I will appreciate any in-depth ideas,

Regards,
Rafal Gicgier

carlos jaramillo on "show product thumbnails in cart"

$
0
0

Hi,

I already manage to show product thumbnails on checkout by creating a review-order.php file on my child theme by adding this code:

<?php echo apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key ) . ' '; ?>

NOW ... I want to show thumbnails on cart as well ...

Any help would be appreciated.

admiralchip on "how to retrive the number of rows returned from a query that uses CONCAT?"

$
0
0

Hello,

I'm currently building a plugin that has a custom search form. In the query, I make use of CONCAT together with an alias and use that in the search along with LIKE. At the moment I'm having trouble returning the number of results found from the search. I tried to use COUNT but that didn't work. My query looks something like this (I'm sorry, I would have copied the actual one it's just that I'm typing this over my phone):

$query = "SELECT id, CONCAT('book_title', ' ', 'volume', ' ', 'ref') as full_title FROM " . $book_table . " WHERE id LIKE '%$book_id%'";
$results = $wpdb->get_results($query);

Now, I'm able to carry out the search and it works however I can't return the number of rows available from the search along with the array. How can I return the number of rows as well? I've used num_rows along with COUNT and num_rows without COUNT.

What I want is, for example, "5 result(s) found" to appear.

Thanks!

tenebris on "Direction-Aware Hover Effect"

$
0
0

I'm trying to add this effect to a page on my site:
http://codepen.io/sloveland/pen/KtDph

I got it working on an index.html page but cannot get it working on wordpress.

Is there a simple, step-by-step, easy to follow method for getting this up and running on wordpress?

I've enqueued the scripts in functions.php page for a child theme and still nothing.

I feel like I'm missing something very, very basic, but I'm very, very new to development so I don't know what that something is and could use assistance.

All I'm trying to do is get this specific effect on a page and have the ability to style it on the backend. Anybody know what to do?

fachrils on "Error Link Image Url"

eastofwest on "Woocommerce Product & Post Category Conflicts"

$
0
0

I'm upgrading an existing site with a Woocommerce store. My urls are pretty and I want to keep them that way, but Woocommerce won't let me.

I know woocommerce says to leave /product/ and /product-category/ in place. I know there's a few expensive plugins that can supposedly achieve this, and I've seen the multiple posts about using the Custom Post Type URL plugin and another hack to get something similar, but let's leave that aside for now.

So it's a destination site where you book & buy stuff - tours, attractions and activities are the product categories.

On the current site which only provides information, the URLs look like this:

Product Category Pages:
visitcapetown.dev/tours/
visitcapetown.dev/attractions/
visitcapetown.dev/activities/

Product Pages:
visitcapetown.dev/tours/craft-beer-tour/
visitcapetown.dev/attractions/table-mountain/
visitcapetown.dev/activities/ultimate-frisbee/

I have managed to get this far in Woocommerce also.

In Woocommerce permalinks admin I set 'Product category base' to '.' and 'Custom Base' to '%product_cat%' plus this plugin:

function add_my_rules() {
   // Interrupt Woo
   $woo_perm = get_option('woocommerce_permalinks');
   $woo_perm['product_base'] = '%product_cat%';
   update_option( 'woocommerce_permalinks', $woo_perm );

   $rules_array = array(
                            ['maincat' => 'tours'],
                            ['maincat' => 'attractions'],
                            ['maincat' => 'activities']
                        );

    foreach ($rules_array as $rule) :
        // ReWrite It
        add_rewrite_rule('('.$rule['maincat'].')/page/?([0-9]{1,})/?$', 'index.php?product_cat='.$rule['maincat'].'&paged=$matches[1]', 'top');
        add_rewrite_rule('('.$rule['maincat'].')/?$', 'index.php?product_cat='.$rule['maincat'], 'top');

    endforeach;

    flush_rewrite_rules();
}
add_action('init', 'add_my_rules');

Almost everything works:
- Products link / work correctly;
- Product categories link / work correctly;
- Normal WordPress pages link / work correctly;
- Normal WordPress post categories link / work correctly;
- Normal WordPress posts >>link<< correctly;

There is just 1 caveat:
- Normal WordPress posts 404.

In admin Permalinks, my post 'Custom Structure' is '/articles/%postname%/'.

If I change that to '/%category%/%postname%/' then the posts work, but the problem moves to Woocommerce products which then 404s.

Even if I add a rewrite rule to test it with a specific URL for a post and tell it where to find that post (the ugly URLs keep on working), it still 404s, so I'm thinking there's a conflicting rule that I can't find.

Can anybody please help with this conflict or explain why this is happening? I will be much appreciated.


admiralchip on "How can I pass some values in wordpress URL to hyperlink a search result?"

$
0
0

Hello,

I'm building a plugin that has a custom search form. I'm using a shortcode to display the search form and every other thing pertaining to the custom search form and it's results. I'm trying to pass the values from the link (like the id) to the wordpress URL so that the page can display the content of the result. So, for example, if I have a URL like this

http://www.mypage.com/special-search

I would like to be able to pass a value like this to identify the result that was clicked on:

http://www.mypage.com/special-search/?link_id=1

I tried doing this but it gives me the "Page not found. Error 404." page.

I've also tried doing it this way but I still get the same problem:

http://www.mypage.com/special-search&link_id=1

I've seen this post, but I've still not been able to get it working:

https://wordpress.org/support/topic/how-to-pass-value-in-wordpress-url?replies=23

How can I fix this?

Thanks in advance!

Abatap on "How to modify header data for admin pages?"

$
0
0

Hello. I need to remove one of the GET parameters from client's browser address bar to prevent duplicate operation. As far as I understand, the only way to do this server-side is to edit the Location header.

Here is a code snippet which is a part of an Order List page in WP Admin panel:

//display the contents of selected order
if (isset($_GET['show_order'])) {
    //see if our user clicked "mark this order processed"
    if (isset($_GET['mark_as_processed'])) {
      //update order status via custom function that uses $wpdb->update
      update_order($_GET['mark_as_processed'], 'Processed');

      //removing the mark_as_processed parameter from client's address bar
      //doesn't do anything
      add_action('send_headers', function() { header('Location: '.$_SERVER['HTTP_REFERER']); });
      //doesn't do anything either, probably because wp_headers isn't called for admin pages
      add_filter('wp_headers', function($headers) { $headers['Location'] = $_SERVER['HTTP_REFERER']; return $headers; });
      //wouldn't work too obviosuly
      header('Location: '.$_SERVER['HTTP_REFERER']);
    }
}

Can anyone tell me what is wrong with my approach? Note that the HTTP_REFERER global contains preciesly what I need in this situation so it's certainly not an issue here. The problem is that these add_filter or add_action functions don't seem to perform any sort of operation.

Kevin on "Inserting portions of loops inside different functions?"

$
0
0

Just wondering about this. Is it possible to divide up portions of loops inside different functions. For instance, say I have the following code:

while( have_rows( 'content' ) ) : the_row(); if( get_row_layout() == 'cool-layout' ) :

How might I be able to accomplish something like the following:

global $content;
$content = 'content';

function begin_layout( $name ) {
  while( have_rows( $content ) ) : the_row(); if( get_row_layout() == $name ) :
}
function end_layout() {
  endif; endwhile;
}

Then in my templates simply initialize and close the layouts with the following:

begin_layout(cool-layout);

  // Content

end_layout();

Obviously the functions I made up don't work, but I was wondering how I might be able to accomplish the same logic?

megseoh on "Reverse Order of Custom Post Type Events"

$
0
0

I've inherited some code that is displaying our events by month but is displaying them beginning with the events that are the furthest away & we would like to reverse the order so that the events that are about to occur appear at the top of the list. Can be seen here http://www.engineering.utoronto.ca/news-events/engineering-events/.

Here is the code:

<?php
$eventArray = array();

$currentMonth = date('n');
$currentYear = date('Y');

//Generate our months from the system time.
for ($i = 12; $i >= $currentMonth; $i--) {
    $monthName = date('F', mktime(0, 0, 0, $i, 10)); // March
    $eventArray[$monthName] = array();
}

$returnData = '';

//Custom Post-Type Events
$args = array(
    'posts_per_page' => -1,
    'offset' => 0,
    'category' => '',
    'orderby' => 'post_date',
    'order' => 'ASC',
    'include' => '',
    'exclude' => '',
    'meta_key' => 'FASE_event_date',
    'orderby' => 'meta_value',
    'post_type' => 'events',
    'post_mime_type' => '',
    'post_parent' => '',
    'post_status' => 'publish',
    'suppress_filters' => true
);
$allData = get_posts($args);

//Search through all our data and sort into months
foreach ($allData as $data) {
    $postDate = strtotime(get_post_meta($data->ID, 'FASE_event_date', true));
    //Check if the index exists.  If so, then populate that data.
    if (array_key_exists(date("F", $postDate), $eventArray)) {
        array_push($eventArray[date("F", $postDate)], $data);
    }
}

foreach ($eventArray as $key => $arrayData) {
    if (count($arrayData) > 0) {
        ?>
        <h2><?php echo $key . ' ' . $currentYear; ?></h2>
        <div class="row">
            <?php
            $reverseArray = array_reverse($arrayData);

            foreach ($reverseArray as $data) {
                if (get_post_meta($data->ID, 'FASE_endDate', true) != "") {
                    $startDay = get_post_meta($data->ID, 'FASE_event_date', true);
                    $endDay = get_post_meta($data->ID, 'FASE_endDate', true);

                    $postDate = date("M j, Y", strtotime($startDay)) . " to " . date("M j, Y", strtotime($endDay));
                } else {
                    $targetTime = get_post_meta($data->ID, 'FASE_event_date', true) . get_post_meta($data->ID, 'FASE_event_date_start', true);
                    $startTime = date("M j, Y g:s A", strtotime($targetTime));
                    $postDate = $startTime;

                    if (get_post_meta($data->ID, 'FASE_event_date_end', true) != '') {
                        $targetTime = get_post_meta($data->ID, 'FASE_event_date_end', true);
                        $postDate .= " to " . $targetTime;
                    }
                }

                $image = get_the_post_thumbnail($data->ID, 'full', array('class' => 'img-responsive'));
                if ($image == "") {
                    $image = '<img src="' . get_template_directory_uri() . '/images/fpo_300x200.jpg' . '" class="img-responsive"/>';
                }
                ?>
                <div class="col-lg-3 col-md-3 col-sm-6 col-xs-6 eventContainer">
                    <a href='<?php echo get_permalink($data->ID); ?>'>
                        <?php echo $image; ?>
                        <h4><?php echo $data->post_title; ?></h4>
                        <p><?php echo $postDate; ?></p>
                    </a>
                </div>
                <?php
            }
            ?>
        </div>
        <?php
    }
}
?>

Things that I have tried to reverse the order of events (that did not work):
- changing 'order' => 'ASC' to 'order' => 'DESC'
- changing array_push($eventArray[date("F", $postDate)], $data); to array_unshift($eventArray[date("F", $postDate)], $data);
- deleting $reverseArray = array_reverse($arrayData); & using $arrayData in the subsequent foreach statement

Any suggestions as to how to reverse the way the months are displaying?

projectagilestudio on "RX form complexity and nd WooCommerce cart"

jlife on "Spam url with iframe?"

$
0
0

Hello Guys,
i need an advice on solving the issue Im facing lately. On my website I found using google indexed pages that are not mine.
You can have a look here http://j-life.eu/what-is-dedicated-server
There are several pages like that showing in search results and I just cant figure out where its coming from. I did the usual stuff, changed passwords, logins, db credentials etc. Search DB for recommended strings and also ftp for some lately changed files /directories. Could not find anything.

Could someone point me in the right direction please?
Thank you

Abatap on "How to modify header data for admin pages?"

$
0
0

Hello. I need to remove one of the GET parameters from client's browser address bar to prevent duplicate operation. As far as I understand, the only way to do this server-side is to edit the Location header.

Here is a code snippet which is a part of an Order List page in WP Admin panel:

//display the contents of selected order
if (isset($_GET['show_order'])) {

    //see if our user clicked "mark this order processed"
    if (isset($_GET['mark_as_processed'])) {

      //update order status via custom function that uses $wpdb->update
      update_order($_GET['mark_as_processed'], 'Processed');

      //removing the mark_as_processed parameter from client's address bar
      //doesn't do anything
      add_action('send_headers', function() { header('Location: '.$_SERVER['HTTP_REFERER']); });

      //doesn't do anything either, probably because wp_headers isn't called for admin pages
      add_filter('wp_headers', function($headers) { $headers['Location'] = $_SERVER['HTTP_REFERER']; return $headers; });

      //wouldn't work too, obviosuly
      header('Location: '.$_SERVER['HTTP_REFERER']);
    }
}

Could anyone tell me what is wrong with my approach here? Note that the HTTP_REFERER global contains precisely what I need in this situation so it's certainly not an issue here. The problem is that these add_filter or add_action functions don't seem to perform any sort of operation on the headers being sent.


Guido on "Custom editor style in child theme"

$
0
0

Hi,

I have created a child theme and want to add my 2-columns shortcode styling in the page/post editor (so the 2 columns are visible while editing a page/post).

So I have added this in child theme file functions:

function my_theme_add_editor_styles() {
	add_editor_style( 'custom-editor-style-child.css' );
}
add_action( 'admin_init', 'my_theme_add_editor_styles' );

But when I copy-paste the shortcode styling from my child theme stylesheet into child theme file 'custom-editor-style-child', no result:

.column_left {width:49%; float:left; margin:0 0 10px; text-align:justify;}
.column_right {width:49%; float:right; margin:0 0 10px; text-align:justify;}

Other changes (such as font-size) are visible.
When am I doing wrong here?

Guido

VitualBob on "Convert blog theme to web site like single page/s"

$
0
0

I'm new to WP but wondered if the blog function in most themes can be turned off. For example, I'm testing a theme called Scrawl https://theme.wordpress.com/themes/scrawl/ because I like its plain appearance.

And each time I post a change it creates a new entry as though I'm writing in a diary (as its meant to do). I'd like it so that I have one page and edits or additions are like on a web site where there's no new 'blog posting'.

Generally, can this blog feature be turned off in blog themes?

charlyanderson on "Featured Image Cropping"

$
0
0

Hello everyone,

I am hoping someone will be able to help me out. I really struggle with image cropping... I am trying to crop the featured images to a vertical rectangle (e.g 5 x 7 photo).

The code I am currently using is:

<?php the_post_thumbnail(array(300, 600 ,true)); // Declare pixel size you need inside the array ?>

However, this does not work. The images crops correctly in width, however, I have lots of empty space where the image doesn't fill the thumbnail height-wise.

Can anyone tell me where I am going wrong please. Thanks in advance.

odie2 on "previous/next_post_link post format when post has no format"

$
0
0

Hello,

I am using at end of post, navigation to previous and next post of certain post type.

<?php

if ( is_page() ) :

    previous_post_link( '%link', __( '<span class="meta-nav">Previous Page</span>%title', 'twentyfourteen' ) );
    next_post_link( '%link', __( '<span class="meta-nav">Next Page</span>%title', 'twentyfourteen' ) );

elseif ( false !== get_post_format() ) :

    previous_post_link( '%link', __( '<span class="meta-nav">Previous '. ucfirst( get_post_format() ) .'</span>%title', 'twentyfourteen' ), TRUE, ' ', 'post_format' );
    next_post_link( '%link', __( '<span class="meta-nav">Next '. ucfirst( get_post_format() ) .'</span>%title', 'twentyfourteen' ), TRUE, ' ', 'post_format' );

else :

    previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'twentyfourteen' ) );

    next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'twentyfourteen' ) );

endif;

?>

But when post has no format, get_post_format() returns false and as I checked in core, there are no any trick, even with filters on wp_get_object_terms as it's getting results from on _term_relationships.

I just would to:

<- Prev Gallery | Current Gallery | Next Gallery ->
<- Prev No-Format Post | Current No-Format Post | Next No-Format Post ->

I could even use any plugin if exists.

Thanks in advance!
Greetings

Funeral on "Pull user database with mysql query?"

$
0
0

Hello I was wondering if anyone could point my in n the right direction. What I'm trying to do is create a clan roster and use the wordpress user id's that way I don't have to keep re-entering them via html.

Viewing all 8245 articles
Browse latest View live




Latest Images